From b5170ed1fd33284b3f7e1caa9070557e8c28a3ca Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Sat, 4 Jan 2014 12:10:22 +0100 Subject: [PATCH 01/89] remove trivial geometry nodes --- Contractor/EdgeBasedGraphFactory.cpp | 310 ++++++++++++++++++--- Contractor/EdgeBasedGraphFactory.h | 61 +++- Contractor/GeometryCompressor.cpp | 175 +++++++++--- Contractor/GeometryCompressor.h | 19 +- DataStructures/OriginalEdgeData.h | 18 +- Server/DataStructures/InternalDataFacade.h | 15 +- Server/DataStructures/SharedDataFacade.h | 1 + Util/GraphLoader.h | 1 + Util/ProgramOptions.h | 4 + prepare.cpp | 17 +- 10 files changed, 503 insertions(+), 118 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index fef577840..0ac515c60 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -33,13 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -//TODO: CompressionWorker -//TODO: EdgeBasedEdgeGenerator - -// template -// inline static void TraverseGraph(NodeBasedDynamicGraph & graph, Work & work) { - -// } +#include EdgeBasedGraphFactory::EdgeBasedGraphFactory( int number_of_nodes, @@ -107,6 +101,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( if(edge.source == edge.target) { continue; } + edge.data.distance = (std::max)((int)import_edge.weight(), 1 ); BOOST_ASSERT( edge.data.distance > 0 ); edge.data.shortcut = false; @@ -115,22 +110,85 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( edge.data.nameID = import_edge.name(); edge.data.type = import_edge.type(); edge.data.isAccessRestricted = import_edge.isAccessRestricted(); - edge.data.edgeBasedNodeID = edges_list.size(); edge.data.contraFlow = import_edge.isContraFlow(); edges_list.push_back( edge ); - if( edge.data.backward ) { - std::swap( edge.source, edge.target ); - edge.data.forward = import_edge.isBackward(); - edge.data.backward = import_edge.isForward(); - edge.data.edgeBasedNodeID = edges_list.size(); - edges_list.push_back( edge ); - } + + std::swap( edge.source, edge.target ); + edge.data.SwapDirectionFlags(); + edges_list.push_back( edge ); } + std::vector().swap(input_edge_list); std::sort( edges_list.begin(), edges_list.end() ); + m_node_based_graph = boost::make_shared( - number_of_nodes, edges_list + number_of_nodes, + edges_list ); + DeallocatingVector().swap(edges_list); + BOOST_ASSERT(0 == edges_list.size() ); +} + +void EdgeBasedGraphFactory::FixupArrivingTurnRestriction( + const NodeID u, + const NodeID v, + const NodeID w +) { + BOOST_ASSERT( u != UINT_MAX ); + BOOST_ASSERT( v != UINT_MAX ); + BOOST_ASSERT( w != UINT_MAX ); + + std::vector predecessors; + for( + EdgeID current_edge_id = m_node_based_graph->BeginEdges(u); + current_edge_id < m_node_based_graph->EndEdges(u); + ++current_edge_id + ) { + const EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge_id); + const NodeID target = m_node_based_graph->GetTarget(current_edge_id); + if( edge_data.backward && ( v != target) ) { + predecessors.push_back(target); + } + } + BOOST_FOREACH( const NodeID x, predecessors ) { + const std::pair restr_start = std::make_pair(x,u); + RestrictionMap::const_iterator restriction_iterator; + restriction_iterator = m_restriction_map.find( restr_start ); + if( restriction_iterator != m_restriction_map.end() ) { + const unsigned index = restriction_iterator->second; + BOOST_FOREACH( + RestrictionTarget & restriction_target, + m_restriction_bucket_list.at(index) + ) { + if( v == restriction_target.first ) { + restriction_target.first = w; + } + } + } + } +} + +void EdgeBasedGraphFactory::FixupStartingTurnRestriction( + const NodeID u, + const NodeID v, + const NodeID w +) { + BOOST_ASSERT( u != UINT_MAX ); + BOOST_ASSERT( v != UINT_MAX ); + BOOST_ASSERT( w != UINT_MAX ); + + const std::pair old_start = std::make_pair(v,w); + RestrictionMap::const_iterator restriction_iterator; + restriction_iterator = m_restriction_map.find( old_start ); + if( restriction_iterator != m_restriction_map.end() ) { + const unsigned index = restriction_iterator->second; + // remove old restriction start (v,w) + m_restriction_map.erase( restriction_iterator ); + + // insert new restriction start (u,w) (point to index) + const std::pair new_start = std::make_pair(u,w); + m_restriction_map.insert( std::make_pair(new_start, index) ); + } } void EdgeBasedGraphFactory::GetEdgeBasedEdges( @@ -157,7 +215,9 @@ NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn( const NodeID u, const NodeID v ) const { - const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v); + BOOST_ASSERT( u != UINT_MAX ); + BOOST_ASSERT( v != UINT_MAX ); + const std::pair restriction_source = std::make_pair(u, v); RestrictionMap::const_iterator restriction_iter; restriction_iter = m_restriction_map.find(restriction_source); if (restriction_iter != m_restriction_map.end()) { @@ -179,8 +239,11 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( const NodeID v, const NodeID w ) const { - //only add an edge if turn is not a U-turn except it is the end of dead-end street. - const std::pair < NodeID, NodeID > restriction_source = std::make_pair(u, v); + BOOST_ASSERT( u != UINT_MAX ); + BOOST_ASSERT( v != UINT_MAX ); + BOOST_ASSERT( w != UINT_MAX ); + + const std::pair restriction_source = std::make_pair(u, v); RestrictionMap::const_iterator restriction_iter; restriction_iter = m_restriction_map.find(restriction_source); if (restriction_iter != m_restriction_map.end()) { @@ -189,7 +252,10 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( const RestrictionTarget & restriction_target, m_restriction_bucket_list.at(index) ) { - if(w == restriction_target.first) { + if( + ( w == restriction_target.first ) && // target found + ( !restriction_target.second ) // and not an only_-restr. + ) { return true; } } @@ -198,10 +264,14 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( } void EdgeBasedGraphFactory::InsertEdgeBasedNode( - EdgeIterator e1, - NodeIterator u, - NodeIterator v, - bool belongsToTinyComponent) { + EdgeIterator e1, + NodeIterator u, + NodeIterator v, + bool belongsToTinyComponent +) { + BOOST_ASSERT( u != UINT_MAX ); + BOOST_ASSERT( v != UINT_MAX ); + BOOST_ASSERT( e1 != UINT_MAX ); EdgeData & data = m_node_based_graph->GetEdgeData(e1); EdgeBasedNode currentNode; currentNode.nameID = data.nameID; @@ -209,6 +279,9 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( currentNode.lon1 = m_node_info_list[u].lon; currentNode.lat2 = m_node_info_list[v].lat; currentNode.lon2 = m_node_info_list[v].lon; + if( m_geometry_compressor.HasEntryForID(e1) ) { + //reconstruct geometry and put in each individual edge with its offset + } currentNode.belongsToTinyComponent = belongsToTinyComponent; currentNode.id = data.edgeBasedNodeID; currentNode.ignoreInGrid = data.ignoreInGrid; @@ -229,27 +302,163 @@ void EdgeBasedGraphFactory::FlushVectorToStream( } void EdgeBasedGraphFactory::Run( - const char * original_edge_data_filename, + const std::string & original_edge_data_filename, + const std::string & geometry_filename, lua_State *lua_state ) { - SimpleLogger().Write() << "Compressing geometry of input graph"; - //TODO: iterate over all turns + SimpleLogger().Write() << "Removing graph geometry while preserving topology"; - //TODO: compress geometries + const unsigned original_number_of_nodes = m_node_based_graph->GetNumberOfNodes(); + const unsigned original_number_of_edges = m_node_based_graph->GetNumberOfEdges(); - //TODO: update turn restrictions if concerned by compression + SimpleLogger().Write(logDEBUG) << "Input graph has " << original_number_of_nodes << " nodes and " << original_number_of_edges << " edges"; + Percent p(original_number_of_nodes); + unsigned removed_node_count = 0; + for( NodeID v = 0; v < original_number_of_nodes; ++v ) { + p.printStatus(v); - //TODO: do some compression statistics + // only contract degree 2 vertices + if( 2 != m_node_based_graph->GetOutDegree(v) ) { + continue; + } + // don't contract barrier node + if( m_barrier_nodes.end() != m_barrier_nodes.find(v) ) { + continue; + } + + const bool reverse_edge_order = !(m_node_based_graph->GetEdgeData(m_node_based_graph->BeginEdges(v)).forward); + const EdgeIterator forward_e2 = m_node_based_graph->BeginEdges(v) + reverse_edge_order; + BOOST_ASSERT( UINT_MAX != forward_e2 ); + const EdgeIterator reverse_e2 = m_node_based_graph->BeginEdges(v) + 1 - reverse_edge_order; + BOOST_ASSERT( UINT_MAX != reverse_e2 ); + + const EdgeData & fwd_edge_data2 = m_node_based_graph->GetEdgeData(forward_e2); + const EdgeData & rev_edge_data2 = m_node_based_graph->GetEdgeData(reverse_e2); + + const NodeIterator w = m_node_based_graph->GetTarget(forward_e2); + BOOST_ASSERT( UINT_MAX != w ); + BOOST_ASSERT( v != w ); + const NodeIterator u = m_node_based_graph->GetTarget(reverse_e2); + BOOST_ASSERT( UINT_MAX != u ); + BOOST_ASSERT( u != v ); + + const EdgeIterator forward_e1 = m_node_based_graph->FindEdge(u, v); + BOOST_ASSERT( UINT_MAX != forward_e1 ); + BOOST_ASSERT( v == m_node_based_graph->GetTarget(forward_e1)); + const EdgeIterator reverse_e1 = m_node_based_graph->FindEdge(w, v); + BOOST_ASSERT( UINT_MAX != reverse_e1 ); + BOOST_ASSERT( v == m_node_based_graph->GetTarget(reverse_e1)); + + const EdgeData & fwd_edge_data1 = m_node_based_graph->GetEdgeData(forward_e1); + const EdgeData & rev_edge_data1 = m_node_based_graph->GetEdgeData(reverse_e1); + + if( m_node_based_graph->FindEdge(u, w) != m_node_based_graph->EndEdges(u) || + m_node_based_graph->FindEdge(w, u) != m_node_based_graph->EndEdges(w) + ) { + continue; + } + + if ( + fwd_edge_data1.IsEqualTo(fwd_edge_data2) && + rev_edge_data1.IsEqualTo(rev_edge_data2) + ) { + // extend e1's to targets of e2's + m_node_based_graph->SetTarget(forward_e1, w); + m_node_based_graph->SetTarget(reverse_e1, u); + + // add weight of e2's to e1 + m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance; + m_node_based_graph->GetEdgeData(reverse_e1).distance += rev_edge_data2.distance; + + // remove e2's (if bidir, otherwise only one) + m_node_based_graph->DeleteEdge(v, forward_e2); + m_node_based_graph->DeleteEdge(v, reverse_e2); + + // update any involved turn restrictions + FixupStartingTurnRestriction( u, v, w ); + FixupArrivingTurnRestriction( u, v, w ); + + FixupStartingTurnRestriction( w, v, u ); + FixupArrivingTurnRestriction( w, v, u ); + + //TODO: store compressed geometry in container + m_geometry_compressor.CompressEdge( forward_e1, forward_e2, v ); + m_geometry_compressor.CompressEdge( reverse_e1, reverse_e2, v ); + + ++removed_node_count; + } + } + SimpleLogger().Write() << "removed " << removed_node_count << " nodes"; + m_geometry_compressor.PrintStatistics(); + + unsigned new_node_count = 0; + unsigned new_edge_count = 0; + for( unsigned i = 0; i < m_node_based_graph->GetNumberOfNodes(); ++i ) { + if( m_node_based_graph->GetOutDegree(i) > 0 ) { + ++new_node_count; + new_edge_count += (m_node_based_graph->EndEdges(i) - m_node_based_graph->BeginEdges(i)); + } + } + SimpleLogger().Write() << "new nodes: " << new_node_count << ", edges " << new_edge_count; + SimpleLogger().Write() << "Node compression ratio: " << new_node_count/(double)original_number_of_nodes; + SimpleLogger().Write() << "Edge compression ratio: " << new_edge_count/(double)original_number_of_edges; + + //Extract routing graph + DeallocatingVector edges_list; + NodeBasedEdge new_edge; + for(NodeID source = 0; source < m_node_based_graph->GetNumberOfNodes(); ++source) { + for( + EdgeID current_edge_id = m_node_based_graph->BeginEdges(source); + current_edge_id < m_node_based_graph->EndEdges(source); + ++current_edge_id + ) { + const NodeID target = m_node_based_graph->GetTarget(current_edge_id); + const EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge_id); + if( source > target ) { + continue; + } + if( edge_data.forward) { + new_edge.source = source; + new_edge.target = target; + new_edge.data = edge_data; + new_edge.data.edgeBasedNodeID = edges_list.size(); + edges_list.push_back(new_edge); + } + + const EdgeID reverse_edge_id = m_node_based_graph->FindEdge(target, source); + BOOST_ASSERT( reverse_edge_id != m_node_based_graph->EndEdges(target)); + + const EdgeData & reverse_edge_data = m_node_based_graph->GetEdgeData(reverse_edge_id); + if( reverse_edge_data.forward ) { + new_edge.source = target; + new_edge.target = source; + new_edge.data = reverse_edge_data; + new_edge.data.edgeBasedNodeID = edges_list.size(); + edges_list.push_back(new_edge); + } + } + } + m_node_based_graph.reset(); + + std::sort( edges_list.begin(), edges_list.end() ); + + //Instantiate routing graph + m_node_based_graph = boost::make_shared( + original_number_of_nodes, + edges_list + ); + + DeallocatingVector().swap(edges_list); + BOOST_ASSERT(0 == edges_list.size() ); SimpleLogger().Write() << "Identifying components of the road network"; - unsigned skipped_turns_counter = 0; unsigned node_based_edge_counter = 0; unsigned original_edges_counter = 0; std::ofstream edge_data_file( - original_edge_data_filename, + original_edge_data_filename.c_str(), std::ios::binary ); @@ -269,8 +478,8 @@ void EdgeBasedGraphFactory::Run( SimpleLogger().Write() << "generating edge-expanded nodes"; - Percent p(m_node_based_graph->GetNumberOfNodes()); - //loop over all edges and generate new set of nodes. + p.reinit(m_node_based_graph->GetNumberOfNodes()); + //loop over all edges and generate new set of nodes for( NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes(); u < end; @@ -322,6 +531,9 @@ void EdgeBasedGraphFactory::Run( //Loop over all turns and generate new set of edges. //Three nested loop look super-linear, but we are dealing with a (kind of) //linear number of turns only. + unsigned restricted_turns_counter = 0; + unsigned skipped_uturns_counter = 0; + unsigned skipped_barrier_turns_counter = 0; p.reinit(m_node_based_graph->GetNumberOfNodes()); for( NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes(); @@ -351,18 +563,18 @@ void EdgeBasedGraphFactory::Run( w != to_node_of_only_restriction ) { //We are at an only_-restriction but not at the right turn. - ++skipped_turns_counter; + ++restricted_turns_counter; continue; } if( is_barrier_node) { if(u != w) { - ++skipped_turns_counter; + ++skipped_barrier_turns_counter; continue; } } else { if ( (u == w) && (m_node_based_graph->GetOutDegree(v) > 1) ) { - ++skipped_turns_counter; + ++skipped_uturns_counter; continue; } } @@ -374,13 +586,13 @@ void EdgeBasedGraphFactory::Run( (to_node_of_only_restriction == UINT_MAX) && (w != to_node_of_only_restriction) ) { - ++skipped_turns_counter; + ++restricted_turns_counter; continue; } //only add an edge if turn is not prohibited - const EdgeData edge_data1 = m_node_based_graph->GetEdgeData(e1); - const EdgeData edge_data2 = m_node_based_graph->GetEdgeData(e2); + const EdgeData & edge_data1 = m_node_based_graph->GetEdgeData(e1); + const EdgeData & edge_data2 = m_node_based_graph->GetEdgeData(e2); BOOST_ASSERT( edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() @@ -406,11 +618,17 @@ void EdgeBasedGraphFactory::Run( } distance += turn_penalty; + const bool edge_is_compressed = m_geometry_compressor.HasEntryForID(e1); + if(edge_is_compressed) { + m_geometry_compressor.AddNodeIDToCompressedEdge(e1, v); + } + original_edge_data_vector.push_back( OriginalEdgeData( - v, + edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v, edge_data2.nameID, - turnInstruction + turnInstruction, + edge_is_compressed ) ); ++original_edges_counter; @@ -442,6 +660,8 @@ void EdgeBasedGraphFactory::Run( edge_data_file.write( (char*)&original_edges_counter, sizeof(unsigned) ); edge_data_file.close(); + m_geometry_compressor.SerializeInternalVector( geometry_filename ); + SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " edge based nodes"; SimpleLogger().Write() << @@ -451,8 +671,12 @@ void EdgeBasedGraphFactory::Run( SimpleLogger().Write() << " contains " << m_edge_based_edge_list.size() << " edges"; SimpleLogger().Write() << - " skips " << skipped_turns_counter << " turns, " + " skips " << restricted_turns_counter << " turns, " "defined by " << m_turn_restrictions_count << " restrictions"; + SimpleLogger().Write() << + " skips " << skipped_uturns_counter << " U turns"; + SimpleLogger().Write() << + " skips " << skipped_barrier_turns_counter << " turns over barriers"; } int EdgeBasedGraphFactory::GetTurnPenalty( diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 4621d752c..d6f75dbd2 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -53,23 +53,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include #include class EdgeBasedGraphFactory : boost::noncopyable { public: - struct SpeedProfileProperties{ - SpeedProfileProperties() : - trafficSignalPenalty(0), - uTurnPenalty(0), - has_turn_penalty_function(false) - { } - - int trafficSignalPenalty; - int uTurnPenalty; - bool has_turn_penalty_function; - } speed_profile; + struct SpeedProfileProperties; explicit EdgeBasedGraphFactory( int number_of_nodes, @@ -78,10 +68,14 @@ public: std::vector & traffic_light_node_list, std::vector & input_restrictions_list, std::vector & m_node_info_list, - SpeedProfileProperties speed_profile + SpeedProfileProperties & speed_profile ); - void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); + void Run( + const std::string & original_edge_data_filename, + const std::string & geometry_filename, + lua_State *myLuaState + ); void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); @@ -102,6 +96,18 @@ public: unsigned GetNumberOfNodes() const; + struct SpeedProfileProperties{ + SpeedProfileProperties() : + trafficSignalPenalty(0), + uTurnPenalty(0), + has_turn_penalty_function(false) + { } + + int trafficSignalPenalty; + int uTurnPenalty; + bool has_turn_penalty_function; + } speed_profile; + private: struct NodeBasedEdgeData { int distance; @@ -115,6 +121,20 @@ private: bool roundabout:1; bool ignoreInGrid:1; bool contraFlow:1; + + void SwapDirectionFlags() { + bool temp_flag = forward; + forward = backward; + backward = temp_flag; + } + + bool IsEqualTo( const NodeBasedEdgeData & other ) const { + return (forward == other.forward) && + (backward == other.backward) && + (nameID == other.nameID) && + (ignoreInGrid == other.ignoreInGrid) && + (contraFlow == other.contraFlow); + } }; unsigned m_turn_restrictions_count; @@ -139,6 +159,7 @@ private: boost::unordered_set m_traffic_lights; RestrictionMap m_restriction_map; + GeometryCompressor m_geometry_compressor; NodeID CheckForEmanatingIsOnlyTurn( const NodeID u, @@ -167,6 +188,18 @@ private: std::ofstream & edge_data_file, std::vector & original_edge_data_vector ) const; + + void FixupArrivingTurnRestriction( + const NodeID u, + const NodeID v, + const NodeID w + ); + + void FixupStartingTurnRestriction( + const NodeID u, + const NodeID v, + const NodeID w + ); }; #endif /* EDGEBASEDGRAPHFACTORY_H_ */ diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 5f97a751c..9e9837bf6 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -26,6 +26,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "GeometryCompressor.h" +#include "../Util/SimpleLogger.h" + +#include +#include + +#include int current_free_list_maximum = 0; int UniqueNumber () { return ++current_free_list_maximum; } @@ -37,58 +43,155 @@ GeometryCompressor::GeometryCompressor() { void GeometryCompressor::IncreaseFreeList() { m_compressed_geometries.resize(m_compressed_geometries.size() + 100); - std::generate_n (m_free_list.rend(), 100, UniqueNumber); + for(unsigned i = 100; i > 0; --i) { + m_free_list.push_back(current_free_list_maximum); + ++current_free_list_maximum; + } } -void GeometryCompressor::AppendNodeIDsToGeomtry( NodeID node_id, NodeID contracted_node_id ) { - //check if node_id already has a list - boost::unordered_map::const_iterator map_iterator; - map_iterator = m_node_id_to_index_map.find( node_id ); +bool GeometryCompressor::HasEntryForID(const EdgeID edge_id) { + return (m_edge_id_to_list_index_map.find(edge_id) != m_edge_id_to_list_index_map.end()); +} - unsigned geometry_bucket_index = std::numeric_limits::max(); - if( m_node_id_to_index_map.end() == map_iterator ) { - //if not, create one - if( m_free_list.empty() ) { - IncreaseFreeList(); +unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) { + boost::unordered_map::const_iterator map_iterator; + map_iterator = m_edge_id_to_list_index_map.find(edge_id); + BOOST_ASSERT( map_iterator != m_edge_id_to_list_index_map.end() ); + return map_iterator->second; +} + +void GeometryCompressor::AddNodeIDToCompressedEdge( + const EdgeID edge_id, + const NodeID node_id +) { + unsigned index = GetPositionForID(edge_id); + BOOST_ASSERT( index < m_compressed_geometries.size() ); + m_compressed_geometries[index].push_back( node_id ); +} + +void GeometryCompressor::SerializeInternalVector( + const std::string & path +) const { + std::ofstream geometry_out_stream( path.c_str(), std::ios::binary ); + const unsigned compressed_edge_count = m_compressed_geometries.size()+1; + BOOST_ASSERT( UINT_MAX != compressed_edge_count ); + geometry_out_stream.write( + (char*)&compressed_edge_count, + sizeof(unsigned) + ); + + // write indices array + unsigned prefix_sum_of_list_indices = 0; + for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) { + const std::vector & current_vector = m_compressed_geometries[i]; + const unsigned unpacked_size = current_vector.size(); + BOOST_ASSERT( UINT_MAX != unpacked_size ); + geometry_out_stream.write( + (char*)&prefix_sum_of_list_indices, + sizeof(unsigned) + ); + prefix_sum_of_list_indices += unpacked_size; + } + // write sentinel element + geometry_out_stream.write( + (char*)&prefix_sum_of_list_indices, + sizeof(unsigned) + ); + + // write compressed geometries + for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) { + const std::vector & current_vector = m_compressed_geometries[i]; + const unsigned unpacked_size = current_vector.size(); + BOOST_ASSERT( UINT_MAX != unpacked_size ); + for(unsigned j = 0; j < unpacked_size; ++j) { + geometry_out_stream.write( + (char*)&(current_vector[j]), + sizeof(unsigned) + ); } - geometry_bucket_index = m_free_list.back(); - m_free_list.pop_back(); - } else { - geometry_bucket_index = map_iterator->second; } - BOOST_ASSERT( std::numeric_limits::max() != geometry_bucket_index ); - BOOST_ASSERT( geometry_bucket_index < m_compressed_geometries.size() ); + // all done, let's close the resource + geometry_out_stream.close(); +} - //append contracted_node_id to m_compressed_geometries[node_id] - m_compressed_geometries[geometry_bucket_index].push_back(contracted_node_id); +void GeometryCompressor::CompressEdge( + const EdgeID surviving_edge_id, + const EdgeID removed_edge_id, + const NodeID via_node_id +) { + BOOST_ASSERT( UINT_MAX != surviving_edge_id ); + BOOST_ASSERT( UINT_MAX != removed_edge_id ); + BOOST_ASSERT( UINT_MAX != via_node_id ); - //append m_compressed_geometries[contracted_node_id] to m_compressed_geometries[node_id] - map_iterator = m_node_id_to_index_map.find(contracted_node_id); - if ( m_node_id_to_index_map.end() != map_iterator) { - const unsigned bucket_index_to_remove = map_iterator->second; - BOOST_ASSERT( bucket_index_to_remove < m_compressed_geometries.size() ); + // append list of removed edge_id plus via node to surviving edge id: + // & compressed_id_list = m_compressed_geometries[surving_list_id]; + compressed_id_list.push_back(via_node_id); + BOOST_ASSERT( 0 < compressed_id_list.size() ); + + // Find any existing list for removed_edge_id + typename boost::unordered_map::const_iterator map_iterator; + map_iterator = m_edge_id_to_list_index_map.find(removed_edge_id); + if( m_edge_id_to_list_index_map.end() != map_iterator ) { + const unsigned index = map_iterator->second; + BOOST_ASSERT( index < m_compressed_geometries.size() ); + // found an existing list, append it to the list of surviving_edge_id + compressed_id_list.insert( + compressed_id_list.end(), + m_compressed_geometries[index].begin(), + m_compressed_geometries[index].end() ); - //remove m_compressed_geometries[contracted_node_id], add to free list - m_compressed_geometries[bucket_index_to_remove].clear(); - m_free_list.push_back(bucket_index_to_remove); + + //remove the list of removed_edge_id + m_edge_id_to_list_index_map.erase(map_iterator); + BOOST_ASSERT( m_edge_id_to_list_index_map.end() == m_edge_id_to_list_index_map.find(removed_edge_id) ); + m_compressed_geometries[index].clear(); + BOOST_ASSERT( 0 == m_compressed_geometries[index].size() ); + m_free_list.push_back(index); + BOOST_ASSERT( index == m_free_list.back() ); } } void GeometryCompressor::PrintStatistics() const { - unsigned compressed_node_count = 0; - const unsigned surviving_node_count = m_compressed_geometries.size(); + unsigned removed_edge_count = 0; + const unsigned surviving_edge_count = m_compressed_geometries.size()-m_free_list.size(); + BOOST_ASSERT( m_compressed_geometries.size() + m_free_list.size() > 0 ); + + unsigned long longest_chain_length = 0; BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) { - compressed_node_count += current_vector.size(); + removed_edge_count += current_vector.size(); + longest_chain_length = std::max(longest_chain_length, current_vector.size()); } + BOOST_ASSERT(0 == surviving_edge_count % 2); SimpleLogger().Write() << - "surv: " << surviving_node_count << - ", comp: " << compressed_node_count << - ", comp ratio: " << ((float)surviving_node_count/std::max(compressed_node_count, 1u) ); + "surviving edges: " << surviving_edge_count << + ", compressed edges: " << removed_edge_count << + ", longest chain length: " << longest_chain_length << + ", comp ratio: " << ((float)surviving_edge_count/std::max(removed_edge_count, 1u) ) << + ", avg: chain length: " << (float)removed_edge_count/std::max(1u, surviving_edge_count); + + SimpleLogger().Write() << + "No bytes: " << 4*surviving_edge_count + removed_edge_count*4; } diff --git a/Contractor/GeometryCompressor.h b/Contractor/GeometryCompressor.h index 8d2bf66a6..1fda18cdb 100644 --- a/Contractor/GeometryCompressor.h +++ b/Contractor/GeometryCompressor.h @@ -25,14 +25,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../Util/SimpleLogger.h" #include "../typedefs.h" -#include -#include #include -#include #include #include @@ -42,17 +38,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class GeometryCompressor { public: GeometryCompressor(); - void AppendNodeIDsToGeomtry( NodeID node_id, NodeID contracted_node_id ); + void CompressEdge( + const EdgeID first_edge_id, + const EdgeID second_edge_id, + const NodeID via_node_id + ); void PrintStatistics() const; + bool HasEntryForID(const EdgeID edge_id); + void AddNodeIDToCompressedEdge(const EdgeID edge_id, const NodeID node_id); + unsigned GetPositionForID(const EdgeID edge_id); + void SerializeInternalVector(const std::string & path) const; private: void IncreaseFreeList(); - std::vector > m_compressed_geometries; + std::vector > m_compressed_geometries; std::vector m_free_list; - boost::unordered_map m_node_id_to_index_map; + boost::unordered_map m_edge_id_to_list_index_map; }; - #endif //GEOMETRY_COMPRESSOR_H diff --git a/DataStructures/OriginalEdgeData.h b/DataStructures/OriginalEdgeData.h index 894cf8add..5ebf98087 100644 --- a/DataStructures/OriginalEdgeData.h +++ b/DataStructures/OriginalEdgeData.h @@ -37,22 +37,26 @@ struct OriginalEdgeData{ explicit OriginalEdgeData( NodeID via_node, unsigned name_id, - TurnInstruction turn_instruction + TurnInstruction turn_instruction, + bool compressed_geometry ) : - via_node(via_node), - name_id(name_id), - turn_instruction(turn_instruction) + via_node( via_node ), + name_id( name_id ), + turn_instruction( turn_instruction ), + compressed_geometry( compressed_geometry ) { } OriginalEdgeData() : - via_node(UINT_MAX), - name_id(UINT_MAX), - turn_instruction(UCHAR_MAX) + via_node( UINT_MAX ), + name_id( UINT_MAX ), + turn_instruction( UCHAR_MAX ), + compressed_geometry( false ) { } NodeID via_node; unsigned name_id; TurnInstruction turn_instruction; + bool compressed_geometry; }; #endif //ORIGINAL_EDGE_DATA_H diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index b8a552cf3..249c37bda 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -113,8 +113,8 @@ private: } void LoadNodeAndEdgeInformation( - const boost::filesystem::path nodes_file, - const boost::filesystem::path edges_file + const boost::filesystem::path & nodes_file, + const boost::filesystem::path & edges_file ) { boost::filesystem::ifstream nodes_input_stream( nodes_file, @@ -163,6 +163,12 @@ private: edges_input_stream.close(); } + void LoadGeometries( + const boost::filesystem::path & geometries_file + ) { + + } + void LoadRTree( const boost::filesystem::path & ram_index_path, const boost::filesystem::path & file_index_path @@ -249,12 +255,17 @@ public: paths_iterator = server_paths.find("namesdata"); BOOST_ASSERT(server_paths.end() != paths_iterator); const boost::filesystem::path & names_data_path = paths_iterator->second; + paths_iterator = server_paths.find("geometries"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + const boost::filesystem::path & geometries_path = paths_iterator->second; //load data SimpleLogger().Write() << "loading graph data"; LoadGraph(hsgr_path); SimpleLogger().Write() << "loading egde information"; LoadNodeAndEdgeInformation(nodes_data_path, edges_data_path); + SimpleLogger().Write() << "loading geometries"; + LoadGeometries( geometries_path ); SimpleLogger().Write() << "loading r-tree"; LoadRTree(ram_index_path, file_index_path); SimpleLogger().Write() << "loading timestamp"; diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 0778eb06d..213b696a2 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -241,6 +241,7 @@ public: LoadGraph(); LoadNodeAndEdgeInformation(); + //TODO: LoadGeometries(); LoadRTree(ram_index_path); LoadTimestamp(); LoadViaNodeList(); diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 9a0a46832..3785da6b2 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../typedefs.h" #include +#include #include #include #include diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index 2c311698f..1b7fbc292 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -110,6 +110,10 @@ inline unsigned GenerateServerProgramOptions( "edgesdata", boost::program_options::value(&paths["edgesdata"]), ".edges file") + ( + "geometries", + boost::program_options::value(&paths["geometries"]), + ".geometries file") ( "ramindex", boost::program_options::value(&paths["ramindex"]), diff --git a/prepare.cpp b/prepare.cpp index 145309e97..43130f0b7 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -183,11 +183,12 @@ int main (int argc, char *argv[]) { std::ifstream in; in.open (input_path.c_str(), std::ifstream::in | std::ifstream::binary); - std::string nodeOut(input_path.string() + ".nodes"); - std::string edgeOut(input_path.string() + ".edges"); - std::string graphOut(input_path.string() + ".hsgr"); - std::string rtree_nodes_path(input_path.string() + ".ramIndex"); - std::string rtree_leafs_path(input_path.string() + ".fileIndex"); + const std::string nodeOut = input_path.string() + ".nodes"; + const std::string edgeOut = input_path.string() + ".edges"; + const std::string geometry_filename = input_path.string() + ".geometry"; + const std::string graphOut = input_path.string() + ".hsgr"; + const std::string rtree_nodes_path = input_path.string() + ".ramIndex"; + const std::string rtree_leafs_path = input_path.string() + ".fileIndex"; /*** Setup Scripting Environment ***/ @@ -254,7 +255,7 @@ int main (int argc, char *argv[]) { SimpleLogger().Write() << "Generating edge-expanded graph representation"; EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile); std::vector().swap(edgeList); - edgeBasedGraphFactory->Run(edgeOut.c_str(), myLuaState); + edgeBasedGraphFactory->Run(edgeOut,geometry_filename, myLuaState); std::vector().swap(inputRestrictions); std::vector().swap(bollardNodes); std::vector().swap(trafficLightNodes); @@ -270,7 +271,7 @@ int main (int argc, char *argv[]) { */ SimpleLogger().Write() << "writing node map ..."; - std::ofstream mapOutFile(nodeOut.c_str(), std::ios::binary); + std::ofstream mapOutFile(nodeOut, std::ios::binary); const unsigned size_of_mapping = internalToExternalNodeMapping.size(); mapOutFile.write((char *)&size_of_mapping, sizeof(unsigned)); mapOutFile.write( @@ -330,7 +331,7 @@ int main (int argc, char *argv[]) { numberOfEdges << " edges"; - std::ofstream hsgr_output_stream(graphOut.c_str(), std::ios::binary); + std::ofstream hsgr_output_stream(graphOut, std::ios::binary); hsgr_output_stream.write((char*)&uuid_orig, sizeof(UUID) ); BOOST_FOREACH(const QueryEdge & edge, contractedEdgeList) { BOOST_ASSERT( UINT_MAX != edge.source ); From 4d132489c16b220578b413e34b46a339623913d4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 29 Jan 2014 11:21:45 +0100 Subject: [PATCH 02/89] remove remnants of C-Style includes --- DataStructures/Coordinate.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/DataStructures/Coordinate.cpp b/DataStructures/Coordinate.cpp index 58598b206..e45931adf 100644 --- a/DataStructures/Coordinate.cpp +++ b/DataStructures/Coordinate.cpp @@ -29,12 +29,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/StringUtil.h" #include -#include -#include +#include FixedPointCoordinate::FixedPointCoordinate() - : lat(INT_MIN), - lon(INT_MIN) + : lat(std::numeric_limits::min()), + lon(std::numeric_limits::min()) { } FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) @@ -43,11 +42,11 @@ FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) { } void FixedPointCoordinate::Reset() { - lat = INT_MIN; - lon = INT_MIN; + lat = std::numeric_limits::min(); + lon = std::numeric_limits::min(); } bool FixedPointCoordinate::isSet() const { - return (INT_MIN != lat) && (INT_MIN != lon); + return (std::numeric_limits::min() != lat) && (std::numeric_limits::min() != lon); } bool FixedPointCoordinate::isValid() const { if( @@ -70,10 +69,10 @@ double FixedPointCoordinate::ApproximateDistance( const int lat2, const int lon2 ) { - BOOST_ASSERT(lat1 != INT_MIN); - BOOST_ASSERT(lon1 != INT_MIN); - BOOST_ASSERT(lat2 != INT_MIN); - BOOST_ASSERT(lon2 != INT_MIN); + BOOST_ASSERT(lat1 != std::numeric_limits::min()); + BOOST_ASSERT(lon1 != std::numeric_limits::min()); + BOOST_ASSERT(lat2 != std::numeric_limits::min()); + BOOST_ASSERT(lon2 != std::numeric_limits::min()); double RAD = 0.017453292519943295769236907684886; double lt1 = lat1/COORDINATE_PRECISION; double ln1 = lon1/COORDINATE_PRECISION; @@ -108,10 +107,10 @@ double FixedPointCoordinate::ApproximateEuclideanDistance( const FixedPointCoordinate &c1, const FixedPointCoordinate &c2 ) { - BOOST_ASSERT(c1.lat != INT_MIN); - BOOST_ASSERT(c1.lon != INT_MIN); - BOOST_ASSERT(c2.lat != INT_MIN); - BOOST_ASSERT(c2.lon != INT_MIN); + BOOST_ASSERT(c1.lat != std::numeric_limits::min()); + BOOST_ASSERT(c1.lon != std::numeric_limits::min()); + BOOST_ASSERT(c2.lat != std::numeric_limits::min()); + BOOST_ASSERT(c2.lon != std::numeric_limits::min()); const double RAD = 0.017453292519943295769236907684886; const double lat1 = (c1.lat/COORDINATE_PRECISION)*RAD; const double lon1 = (c1.lon/COORDINATE_PRECISION)*RAD; From 7083978f9d23b122aefc3ee23bf8bd605e99463f Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 29 Jan 2014 11:30:04 +0100 Subject: [PATCH 03/89] remove remnants of C-Style includes --- DataStructures/OriginalEdgeData.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DataStructures/OriginalEdgeData.h b/DataStructures/OriginalEdgeData.h index 5ebf98087..48653cbb6 100644 --- a/DataStructures/OriginalEdgeData.h +++ b/DataStructures/OriginalEdgeData.h @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "TurnInstructions.h" #include "../typedefs.h" -#include +#include struct OriginalEdgeData{ explicit OriginalEdgeData( @@ -47,9 +47,9 @@ struct OriginalEdgeData{ { } OriginalEdgeData() : - via_node( UINT_MAX ), - name_id( UINT_MAX ), - turn_instruction( UCHAR_MAX ), + via_node( std::numeric_limits::max() ), + name_id( std::numeric_limits::max() ), + turn_instruction( std::numeric_limits::max() ), compressed_geometry( false ) { } From cd6874ca60ae87b251bce5a5b0b6d27d78fc3bb8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 29 Jan 2014 11:30:34 +0100 Subject: [PATCH 04/89] remove remnants of C-Style includes --- DataStructures/QueryEdge.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/DataStructures/QueryEdge.h b/DataStructures/QueryEdge.h index 41c9e066f..0e71ab701 100644 --- a/DataStructures/QueryEdge.h +++ b/DataStructures/QueryEdge.h @@ -30,8 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../typedefs.h" -#include - struct QueryEdge { NodeID source; NodeID target; From 3be644265b363f192457b862cb2ec3bcc2d3c831 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 29 Jan 2014 11:31:39 +0100 Subject: [PATCH 05/89] remove remnants of C-Style includes --- DataStructures/Restriction.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/DataStructures/Restriction.h b/DataStructures/Restriction.h index 429cc8acd..153c5afc9 100644 --- a/DataStructures/Restriction.h +++ b/DataStructures/Restriction.h @@ -29,7 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RESTRICTION_H_ #include "../typedefs.h" -#include + +#include struct TurnRestriction { NodeID viaNode; @@ -60,8 +61,8 @@ struct TurnRestriction { explicit TurnRestriction(NodeID viaNode) : viaNode(viaNode), - fromNode(UINT_MAX), - toNode(UINT_MAX) { + fromNode(std::numeric_limits::max()), + toNode(std::numeric_limits::max()) { } explicit TurnRestriction(const bool isOnly = false) : @@ -93,9 +94,9 @@ struct InputRestrictionContainer { explicit InputRestrictionContainer( bool isOnly = false ) : - fromWay(UINT_MAX), - toWay(UINT_MAX), - viaNode(UINT_MAX) + fromWay(std::numeric_limits::max()), + toWay(std::numeric_limits::max()), + viaNode(std::numeric_limits::max()) { restriction.flags.isOnly = isOnly; } @@ -105,10 +106,10 @@ struct InputRestrictionContainer { } static InputRestrictionContainer max_value() { return InputRestrictionContainer( - UINT_MAX, - UINT_MAX, - UINT_MAX, - UINT_MAX + std::numeric_limits::max(), + std::numeric_limits::max(), + std::numeric_limits::max(), + std::numeric_limits::max() ); } }; From c71c8b0047034e9c1235d7f8fd137a17d961cc7c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 11 Feb 2014 11:42:24 +0100 Subject: [PATCH 06/89] Unpacking of intermediate paths --- Contractor/EdgeBasedGraphFactory.cpp | 293 ++++++++++++++------- Contractor/EdgeBasedGraphFactory.h | 13 +- Contractor/GeometryCompressor.cpp | 138 ++++++---- Contractor/GeometryCompressor.h | 23 +- DataStructures/EdgeBasedNode.h | 89 +++++-- DataStructures/ImportEdge.h | 2 +- DataStructures/PhantomNodes.h | 50 ++-- DataStructures/QueryNode.h | 17 +- DataStructures/StaticRTree.h | 184 +------------ Descriptors/DescriptionFactory.cpp | 10 +- Descriptors/DescriptionFactory.h | 4 +- RoutingAlgorithms/AlternativePathRouting.h | 24 +- RoutingAlgorithms/BasicRoutingInterface.h | 52 +++- RoutingAlgorithms/ShortestPathRouting.h | 48 ++-- Server/DataStructures/BaseDataFacade.h | 9 + Server/DataStructures/InternalDataFacade.h | 86 +++++- Server/DataStructures/SharedDataFacade.h | 19 +- Util/ProgramOptions.h | 15 +- prepare.cpp | 5 +- routed.cpp | 1 + 20 files changed, 639 insertions(+), 443 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 0ac515c60..27318b23b 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -45,6 +45,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( SpeedProfileProperties speed_profile ) : speed_profile(speed_profile), m_turn_restrictions_count(0), + m_number_of_edge_based_nodes(std::numeric_limits::max()), m_node_info_list(node_info_list) { BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { @@ -106,7 +107,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( BOOST_ASSERT( edge.data.distance > 0 ); edge.data.shortcut = false; edge.data.roundabout = import_edge.isRoundabout(); - edge.data.ignoreInGrid = import_edge.ignoreInGrid(); + edge.data.ignore_in_grid = import_edge.ignoreInGrid(); edge.data.nameID = import_edge.name(); edge.data.type = import_edge.type(); edge.data.isAccessRestricted = import_edge.isAccessRestricted(); @@ -134,9 +135,9 @@ void EdgeBasedGraphFactory::FixupArrivingTurnRestriction( const NodeID v, const NodeID w ) { - BOOST_ASSERT( u != UINT_MAX ); - BOOST_ASSERT( v != UINT_MAX ); - BOOST_ASSERT( w != UINT_MAX ); + BOOST_ASSERT( u != std::numeric_limits::max() ); + BOOST_ASSERT( v != std::numeric_limits::max() ); + BOOST_ASSERT( w != std::numeric_limits::max() ); std::vector predecessors; for( @@ -173,9 +174,9 @@ void EdgeBasedGraphFactory::FixupStartingTurnRestriction( const NodeID v, const NodeID w ) { - BOOST_ASSERT( u != UINT_MAX ); - BOOST_ASSERT( v != UINT_MAX ); - BOOST_ASSERT( w != UINT_MAX ); + BOOST_ASSERT( u != std::numeric_limits::max() ); + BOOST_ASSERT( v != std::numeric_limits::max() ); + BOOST_ASSERT( w != std::numeric_limits::max() ); const std::pair old_start = std::make_pair(v,w); RestrictionMap::const_iterator restriction_iterator; @@ -215,8 +216,8 @@ NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn( const NodeID u, const NodeID v ) const { - BOOST_ASSERT( u != UINT_MAX ); - BOOST_ASSERT( v != UINT_MAX ); + BOOST_ASSERT( u != std::numeric_limits::max() ); + BOOST_ASSERT( v != std::numeric_limits::max() ); const std::pair restriction_source = std::make_pair(u, v); RestrictionMap::const_iterator restriction_iter; restriction_iter = m_restriction_map.find(restriction_source); @@ -231,7 +232,7 @@ NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn( } } } - return UINT_MAX; + return std::numeric_limits::max(); } bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( @@ -239,9 +240,9 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( const NodeID v, const NodeID w ) const { - BOOST_ASSERT( u != UINT_MAX ); - BOOST_ASSERT( v != UINT_MAX ); - BOOST_ASSERT( w != UINT_MAX ); + BOOST_ASSERT( u != std::numeric_limits::max() ); + BOOST_ASSERT( v != std::numeric_limits::max() ); + BOOST_ASSERT( w != std::numeric_limits::max() ); const std::pair restriction_source = std::make_pair(u, v); RestrictionMap::const_iterator restriction_iter; @@ -264,29 +265,85 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( } void EdgeBasedGraphFactory::InsertEdgeBasedNode( - EdgeIterator e1, NodeIterator u, NodeIterator v, - bool belongsToTinyComponent + bool belongs_to_tiny_cc ) { - BOOST_ASSERT( u != UINT_MAX ); - BOOST_ASSERT( v != UINT_MAX ); - BOOST_ASSERT( e1 != UINT_MAX ); - EdgeData & data = m_node_based_graph->GetEdgeData(e1); - EdgeBasedNode currentNode; - currentNode.nameID = data.nameID; - currentNode.lat1 = m_node_info_list[u].lat; - currentNode.lon1 = m_node_info_list[u].lon; - currentNode.lat2 = m_node_info_list[v].lat; - currentNode.lon2 = m_node_info_list[v].lon; - if( m_geometry_compressor.HasEntryForID(e1) ) { - //reconstruct geometry and put in each individual edge with its offset + // merge edges together into one EdgeBasedNode + BOOST_ASSERT( u != std::numeric_limits::max() ); + BOOST_ASSERT( v != std::numeric_limits::max() ); + + // find forward edge id and + const EdgeID e1 = m_node_based_graph->FindEdge(u, v); + BOOST_ASSERT( e1 != std::numeric_limits::max() ); + const EdgeData & forward_data = m_node_based_graph->GetEdgeData(e1); + + if( forward_data.ignore_in_grid ) { + // SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," << + // m_node_info_list[u].lon << " - " << + // m_node_info_list[v].lat << "," << + // m_node_info_list[v].lon; + + return; } - currentNode.belongsToTinyComponent = belongsToTinyComponent; - currentNode.id = data.edgeBasedNodeID; - currentNode.ignoreInGrid = data.ignoreInGrid; - currentNode.weight = data.distance; - m_edge_based_node_list.push_back(currentNode); + + // find reverse edge id and + const EdgeID e2 = m_node_based_graph->FindEdge(v, u); + BOOST_ASSERT( e2 != std::numeric_limits::max() ); + const EdgeData & reverse_data = m_node_based_graph->GetEdgeData(e2); + + if( m_geometry_compressor.HasEntryForID(e1) ) { + BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e2) ); + + // reconstruct geometry and put in each individual edge with its offset + const std::vector & forward_geometry = m_geometry_compressor.GetBucketReference(e1); + const std::vector & reverse_geometry = m_geometry_compressor.GetBucketReference(e2); + BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); + BOOST_ASSERT( 0 != forward_geometry.size() ); + for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { + if( forward_geometry[i].first != reverse_geometry[reverse_geometry.size()-1-i].first ) { +#ifndef NDEBUG + SimpleLogger().Write() << "size1: " << forward_geometry.size() << ", size2: " << reverse_geometry.size(); + SimpleLogger().Write() << "index1: " << i << ", index2: " << reverse_geometry.size()-1-i; + SimpleLogger().Write() << forward_geometry[0].first << "!=" << reverse_geometry[reverse_geometry.size()-1-i].first; + BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, forward_geometry) { + SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; + } + BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { + SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; + } +#endif + } + BOOST_ASSERT( forward_geometry[i].first == reverse_geometry[reverse_geometry.size()-1-i].first ); + + //TODO reconstruct bidirectional edge with weights. + + + + + } + // SimpleLogger().Write(logDEBUG) << "start " << m_node_info_list[u].lat << "," << m_node_info_list[u].lon; + // SimpleLogger().Write(logDEBUG) << "target " << m_node_info_list[v].lat << "," << m_node_info_list[v].lon; + // BOOST_ASSERT( false ); + } //else { + //TODO: emplace back with C++11 + m_edge_based_node_list.push_back( + EdgeBasedNode( + forward_data.edgeBasedNodeID, + reverse_data.edgeBasedNodeID, + m_node_info_list[u].lat, + m_node_info_list[u].lon, + m_node_info_list[v].lat, + m_node_info_list[v].lon, + belongs_to_tiny_cc, + forward_data.nameID, //TODO use also reverse name id? + forward_data.distance, + reverse_data.distance, + 0, + 0 + ) + ); + // } } @@ -329,25 +386,25 @@ void EdgeBasedGraphFactory::Run( const bool reverse_edge_order = !(m_node_based_graph->GetEdgeData(m_node_based_graph->BeginEdges(v)).forward); const EdgeIterator forward_e2 = m_node_based_graph->BeginEdges(v) + reverse_edge_order; - BOOST_ASSERT( UINT_MAX != forward_e2 ); + BOOST_ASSERT( std::numeric_limits::max() != forward_e2 ); const EdgeIterator reverse_e2 = m_node_based_graph->BeginEdges(v) + 1 - reverse_edge_order; - BOOST_ASSERT( UINT_MAX != reverse_e2 ); + BOOST_ASSERT( std::numeric_limits::max() != reverse_e2 ); const EdgeData & fwd_edge_data2 = m_node_based_graph->GetEdgeData(forward_e2); const EdgeData & rev_edge_data2 = m_node_based_graph->GetEdgeData(reverse_e2); const NodeIterator w = m_node_based_graph->GetTarget(forward_e2); - BOOST_ASSERT( UINT_MAX != w ); + BOOST_ASSERT( std::numeric_limits::max() != w ); BOOST_ASSERT( v != w ); const NodeIterator u = m_node_based_graph->GetTarget(reverse_e2); - BOOST_ASSERT( UINT_MAX != u ); + BOOST_ASSERT( std::numeric_limits::max() != u ); BOOST_ASSERT( u != v ); const EdgeIterator forward_e1 = m_node_based_graph->FindEdge(u, v); - BOOST_ASSERT( UINT_MAX != forward_e1 ); + BOOST_ASSERT( std::numeric_limits::max() != forward_e1 ); BOOST_ASSERT( v == m_node_based_graph->GetTarget(forward_e1)); const EdgeIterator reverse_e1 = m_node_based_graph->FindEdge(w, v); - BOOST_ASSERT( UINT_MAX != reverse_e1 ); + BOOST_ASSERT( std::numeric_limits::max() != reverse_e1 ); BOOST_ASSERT( v == m_node_based_graph->GetTarget(reverse_e1)); const EdgeData & fwd_edge_data1 = m_node_based_graph->GetEdgeData(forward_e1); @@ -367,6 +424,12 @@ void EdgeBasedGraphFactory::Run( m_node_based_graph->SetTarget(forward_e1, w); m_node_based_graph->SetTarget(reverse_e1, u); + const int forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; + // const int forward_weight2 = fwd_edge_data2.distance; + + const int reverse_weight1 = m_node_based_graph->GetEdgeData(reverse_e1).distance; + // const int reverse_weight2 = rev_edge_data2.distance; + // add weight of e2's to e1 m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance; m_node_based_graph->GetEdgeData(reverse_e1).distance += rev_edge_data2.distance; @@ -382,9 +445,21 @@ void EdgeBasedGraphFactory::Run( FixupStartingTurnRestriction( w, v, u ); FixupArrivingTurnRestriction( w, v, u ); - //TODO: store compressed geometry in container - m_geometry_compressor.CompressEdge( forward_e1, forward_e2, v ); - m_geometry_compressor.CompressEdge( reverse_e1, reverse_e2, v ); + // store compressed geometry in container + m_geometry_compressor.CompressEdge( + forward_e1, + forward_e2, + v, + forward_weight1//, + // forward_weight2 + ); + m_geometry_compressor.CompressEdge( + reverse_e1, + reverse_e2, + v, + reverse_weight1//, + // reverse_weight2 + ); ++removed_node_count; } @@ -405,8 +480,7 @@ void EdgeBasedGraphFactory::Run( SimpleLogger().Write() << "Edge compression ratio: " << new_edge_count/(double)original_number_of_edges; //Extract routing graph - DeallocatingVector edges_list; - NodeBasedEdge new_edge; + unsigned numbered_edges_count = 0; for(NodeID source = 0; source < m_node_based_graph->GetNumberOfNodes(); ++source) { for( EdgeID current_edge_id = m_node_based_graph->BeginEdges(source); @@ -414,44 +488,37 @@ void EdgeBasedGraphFactory::Run( ++current_edge_id ) { const NodeID target = m_node_based_graph->GetTarget(current_edge_id); - const EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge_id); - if( source > target ) { + EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge_id); + if( 0 == numbered_edges_count ){ + SimpleLogger().Write(logDEBUG) << "uninitialized edge based node id: " << edge_data.edgeBasedNodeID; + } + if( !edge_data.forward ) { + // SimpleLogger().Write(logDEBUG) << "skipped edge (" << source << "," << target << ")=[" << current_edge_id << "]"; continue; } - if( edge_data.forward) { - new_edge.source = source; - new_edge.target = target; - new_edge.data = edge_data; - new_edge.data.edgeBasedNodeID = edges_list.size(); - edges_list.push_back(new_edge); + if( edge_data.edgeBasedNodeID != std::numeric_limits::max() ) {//source > target ) { + // SimpleLogger().Write(logDEBUG) << "skipping edge based node id: " << edge_data.edgeBasedNodeID; + continue; } + BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); + edge_data.edgeBasedNodeID = numbered_edges_count; + ++numbered_edges_count; + const EdgeID reverse_edge_id = m_node_based_graph->FindEdge(target, source); BOOST_ASSERT( reverse_edge_id != m_node_based_graph->EndEdges(target)); - const EdgeData & reverse_edge_data = m_node_based_graph->GetEdgeData(reverse_edge_id); - if( reverse_edge_data.forward ) { - new_edge.source = target; - new_edge.target = source; - new_edge.data = reverse_edge_data; - new_edge.data.edgeBasedNodeID = edges_list.size(); - edges_list.push_back(new_edge); + EdgeData & reverse_edge_data = m_node_based_graph->GetEdgeData(reverse_edge_id); + if( !reverse_edge_data.forward ) { + continue; } + + BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); + reverse_edge_data.edgeBasedNodeID = numbered_edges_count; + ++numbered_edges_count; } } - m_node_based_graph.reset(); - - std::sort( edges_list.begin(), edges_list.end() ); - - //Instantiate routing graph - m_node_based_graph = boost::make_shared( - original_number_of_nodes, - edges_list - ); - - DeallocatingVector().swap(edges_list); - BOOST_ASSERT(0 == edges_list.size() ); - + SimpleLogger().Write(logDEBUG) << "numbered " << numbered_edges_count << " edge-expanded nodes"; SimpleLogger().Write() << "Identifying components of the road network"; unsigned node_based_edge_counter = 0; @@ -479,12 +546,15 @@ void EdgeBasedGraphFactory::Run( "generating edge-expanded nodes"; p.reinit(m_node_based_graph->GetNumberOfNodes()); + //loop over all edges and generate new set of nodes for( NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes(); u < end; ++u ) { + BOOST_ASSERT( u != std::numeric_limits::max() ); + BOOST_ASSERT( u < m_node_based_graph->GetNumberOfNodes() ); p.printIncrement(); for( EdgeIterator e1 = m_node_based_graph->BeginEdges(u), @@ -492,24 +562,32 @@ void EdgeBasedGraphFactory::Run( e1 < last_edge; ++e1 ) { + BOOST_ASSERT( e1 != std::numeric_limits::max() ); NodeIterator v = m_node_based_graph->GetTarget(e1); + BOOST_ASSERT( std::numeric_limits::max() != v ); + // pick only every other edge + if( u > v ) { + continue; + } + BOOST_ASSERT( u < v ); + BOOST_ASSERT( + m_node_based_graph->GetEdgeData(e1).type != SHRT_MAX + ); - if(m_node_based_graph->GetEdgeData(e1).type != SHRT_MAX) { - BOOST_ASSERT_MSG(e1 != UINT_MAX, "edge id invalid"); - BOOST_ASSERT_MSG(u != UINT_MAX, "souce node invalid"); - BOOST_ASSERT_MSG(v != UINT_MAX, "target node invalid"); //Note: edges that end on barrier nodes or on a turn restriction //may actually be in two distinct components. We choose the smallest - const unsigned size_of_component = std::min( - component_index_size[component_index_list[u]], - component_index_size[component_index_list[v]] - ); + const unsigned size_of_component = std::min( + component_index_size[component_index_list[u]], + component_index_size[component_index_list[v]] + ); - InsertEdgeBasedNode( e1, u, v, size_of_component < 1000 ); - } + InsertEdgeBasedNode( u, v, size_of_component < 1000 ); } } + //TODO: check if correct, suspect two off by ones here + m_number_of_edge_based_nodes = numbered_edges_count; + SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " nodes in " << "edge-expanded graph"; @@ -534,6 +612,7 @@ void EdgeBasedGraphFactory::Run( unsigned restricted_turns_counter = 0; unsigned skipped_uturns_counter = 0; unsigned skipped_barrier_turns_counter = 0; + unsigned compressed = 0; p.reinit(m_node_based_graph->GetNumberOfNodes()); for( NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes(); @@ -546,6 +625,10 @@ void EdgeBasedGraphFactory::Run( e1 < last_edge_u; ++e1 ) { + if( !m_node_based_graph->GetEdgeData(e1).forward ) { + continue; + } + ++node_based_edge_counter; const NodeIterator v = m_node_based_graph->GetTarget(e1); const NodeID to_node_of_only_restriction = CheckForEmanatingIsOnlyTurn(u, v); @@ -557,9 +640,12 @@ void EdgeBasedGraphFactory::Run( e2 < last_edge_v; ++e2 ) { + if( !m_node_based_graph->GetEdgeData(e2).forward ) { + continue; + } const NodeIterator w = m_node_based_graph->GetTarget(e2); if( - to_node_of_only_restriction != UINT_MAX && + to_node_of_only_restriction != std::numeric_limits::max() && w != to_node_of_only_restriction ) { //We are at an only_-restriction but not at the right turn. @@ -583,7 +669,7 @@ void EdgeBasedGraphFactory::Run( //at the end of a dead-end street if ( CheckIfTurnIsRestricted(u, v, w) && - (to_node_of_only_restriction == UINT_MAX) && + (to_node_of_only_restriction == std::numeric_limits::max()) && (w != to_node_of_only_restriction) ) { ++restricted_turns_counter; @@ -594,12 +680,12 @@ void EdgeBasedGraphFactory::Run( const EdgeData & edge_data1 = m_node_based_graph->GetEdgeData(e1); const EdgeData & edge_data2 = m_node_based_graph->GetEdgeData(e2); - BOOST_ASSERT( - edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() - ); - BOOST_ASSERT( - edge_data2.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() - ); + // BOOST_ASSERT( + // edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() + // ); + // BOOST_ASSERT( + // edge_data2.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() + // ); BOOST_ASSERT( edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID ); @@ -612,22 +698,26 @@ void EdgeBasedGraphFactory::Run( distance += speed_profile.trafficSignalPenalty; } const int turn_penalty = GetTurnPenalty(u, v, w, lua_state); - TurnInstruction turnInstruction = AnalyzeTurn(u, v, w); - if(turnInstruction == TurnInstructions.UTurn){ + TurnInstruction turn_instruction = AnalyzeTurn(u, v, w); + if(turn_instruction == TurnInstructions.UTurn){ distance += speed_profile.uTurnPenalty; } distance += turn_penalty; const bool edge_is_compressed = m_geometry_compressor.HasEntryForID(e1); if(edge_is_compressed) { - m_geometry_compressor.AddNodeIDToCompressedEdge(e1, v); + ++compressed; + m_geometry_compressor.AddLastViaNodeIDToCompressedEdge(e1, v, /*TODO*/ 1); + if ( 0 == m_geometry_compressor.GetPositionForID(e1) ) { + SimpleLogger().Write(logDEBUG) << "e1: " << e1 << " is zero with via node: " << v; + } } original_edge_data_vector.push_back( OriginalEdgeData( - edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v, + (edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v), edge_data2.nameID, - turnInstruction, + turn_instruction, edge_is_compressed ) ); @@ -656,10 +746,13 @@ void EdgeBasedGraphFactory::Run( } FlushVectorToStream( edge_data_file, original_edge_data_vector ); + SimpleLogger().Write(logDEBUG) << "compressed: " << compressed; + edge_data_file.seekp( std::ios::beg ); edge_data_file.write( (char*)&original_edges_counter, sizeof(unsigned) ); edge_data_file.close(); + SimpleLogger().Write(logDEBUG) << "serializing geometry to " << geometry_filename; m_geometry_compressor.SerializeInternalVector( geometry_filename ); SimpleLogger().Write() << @@ -769,8 +862,8 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( return TurnInstructions.GetTurnDirectionOfInstruction(angle); } -unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const { - return m_node_based_graph->GetNumberOfEdges(); +unsigned EdgeBasedGraphFactory::GetNumberOfEdgeBasedNodes() const { + return m_number_of_edge_based_nodes; } void EdgeBasedGraphFactory::BFSCompentExplorer( @@ -787,12 +880,12 @@ void EdgeBasedGraphFactory::BFSCompentExplorer( component_index_list.resize( m_node_based_graph->GetNumberOfNodes(), - UINT_MAX + std::numeric_limits::max() ); //put unexplorered node with parent pointer into queue for( NodeID node = 0, end = m_node_based_graph->GetNumberOfNodes(); node < end; ++node) { - if(UINT_MAX == component_index_list[node]) { + if(std::numeric_limits::max() == component_index_list[node]) { bfs_queue.push(std::make_pair(node, node)); //mark node as read component_index_list[node] = current_component; @@ -818,7 +911,7 @@ void EdgeBasedGraphFactory::BFSCompentExplorer( NodeIterator w = m_node_based_graph->GetTarget(e2); if( - to_node_of_only_restriction != UINT_MAX && + to_node_of_only_restriction != std::numeric_limits::max() && w != to_node_of_only_restriction ) { // At an only_-restriction but not at the right turn @@ -829,7 +922,7 @@ void EdgeBasedGraphFactory::BFSCompentExplorer( //when it is at the end of a dead-end street. if (!CheckIfTurnIsRestricted(u, v, w) ) { //only add an edge if turn is not prohibited - if(UINT_MAX == component_index_list[w]) { + if(std::numeric_limits::max() == component_index_list[w]) { //insert next (node, parent) only if w has //not yet been explored //mark node as read diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index d6f75dbd2..f8269c2f8 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -94,7 +94,7 @@ public: lua_State *myLuaState ) const; - unsigned GetNumberOfNodes() const; + unsigned GetNumberOfEdgeBasedNodes() const; struct SpeedProfileProperties{ SpeedProfileProperties() : @@ -110,6 +110,11 @@ public: private: struct NodeBasedEdgeData { + NodeBasedEdgeData() { + //TODO: proper c'tor + edgeBasedNodeID = UINT_MAX; + } + int distance; unsigned edgeBasedNodeID; unsigned nameID; @@ -119,7 +124,7 @@ private: bool forward:1; bool backward:1; bool roundabout:1; - bool ignoreInGrid:1; + bool ignore_in_grid:1; bool contraFlow:1; void SwapDirectionFlags() { @@ -132,12 +137,13 @@ private: return (forward == other.forward) && (backward == other.backward) && (nameID == other.nameID) && - (ignoreInGrid == other.ignoreInGrid) && + (ignore_in_grid == other.ignore_in_grid) && (contraFlow == other.contraFlow); } }; unsigned m_turn_restrictions_count; + unsigned m_number_of_edge_based_nodes; typedef DynamicGraph NodeBasedDynamicGraph; typedef NodeBasedDynamicGraph::InputEdge NodeBasedEdge; @@ -173,7 +179,6 @@ private: ) const; void InsertEdgeBasedNode( - NodeBasedDynamicGraph::EdgeIterator e1, NodeBasedDynamicGraph::NodeIterator u, NodeBasedDynamicGraph::NodeIterator v, bool belongsToTinyComponent diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 9e9837bf6..83157a27d 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -37,7 +37,7 @@ int current_free_list_maximum = 0; int UniqueNumber () { return ++current_free_list_maximum; } GeometryCompressor::GeometryCompressor() { - m_free_list.resize(100); + m_free_list.reserve(100); IncreaseFreeList(); } @@ -49,68 +49,91 @@ void GeometryCompressor::IncreaseFreeList() { } } -bool GeometryCompressor::HasEntryForID(const EdgeID edge_id) { +bool GeometryCompressor::HasEntryForID(const EdgeID edge_id) const { return (m_edge_id_to_list_index_map.find(edge_id) != m_edge_id_to_list_index_map.end()); } -unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) { +unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const { boost::unordered_map::const_iterator map_iterator; map_iterator = m_edge_id_to_list_index_map.find(edge_id); BOOST_ASSERT( map_iterator != m_edge_id_to_list_index_map.end() ); + BOOST_ASSERT( map_iterator->second < m_compressed_geometries.size() ); return map_iterator->second; } -void GeometryCompressor::AddNodeIDToCompressedEdge( +void GeometryCompressor::AddLastViaNodeIDToCompressedEdge( const EdgeID edge_id, - const NodeID node_id + const NodeID node_id, + const EdgeWeight weight ) { unsigned index = GetPositionForID(edge_id); BOOST_ASSERT( index < m_compressed_geometries.size() ); - m_compressed_geometries[index].push_back( node_id ); + if( !m_compressed_geometries[index].empty() ) { + if( m_compressed_geometries[index].back().first == node_id ) { + return; + } + } + BOOST_ASSERT( node_id != m_compressed_geometries[index].back().first ); + m_compressed_geometries[index].push_back( std::make_pair(node_id, weight) ); + BOOST_ASSERT( node_id == m_compressed_geometries[index].back().first ); } void GeometryCompressor::SerializeInternalVector( const std::string & path ) const { + //TODO: remove super-trivial geometries + std::ofstream geometry_out_stream( path.c_str(), std::ios::binary ); - const unsigned compressed_edge_count = m_compressed_geometries.size()+1; - BOOST_ASSERT( UINT_MAX != compressed_edge_count ); + const unsigned number_of_compressed_geometries = m_compressed_geometries.size()+1; + BOOST_ASSERT( UINT_MAX != number_of_compressed_geometries ); geometry_out_stream.write( - (char*)&compressed_edge_count, + (char*)&number_of_compressed_geometries, sizeof(unsigned) ); + SimpleLogger().Write(logDEBUG) << "number_of_compressed_geometries: " << number_of_compressed_geometries; + // write indices array unsigned prefix_sum_of_list_indices = 0; for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) { - const std::vector & current_vector = m_compressed_geometries[i]; - const unsigned unpacked_size = current_vector.size(); - BOOST_ASSERT( UINT_MAX != unpacked_size ); geometry_out_stream.write( (char*)&prefix_sum_of_list_indices, sizeof(unsigned) ); + + const std::vector & current_vector = m_compressed_geometries.at(i); + const unsigned unpacked_size = current_vector.size(); + BOOST_ASSERT( UINT_MAX != unpacked_size ); prefix_sum_of_list_indices += unpacked_size; } - // write sentinel element + // sentinel element geometry_out_stream.write( (char*)&prefix_sum_of_list_indices, sizeof(unsigned) ); + // number of geometry entries to follow, it is the (inclusive) prefix sum + geometry_out_stream.write( + (char*)&prefix_sum_of_list_indices, + sizeof(unsigned) + ); + + SimpleLogger().Write(logDEBUG) << "number of geometry nodes: " << prefix_sum_of_list_indices; + unsigned control_sum = 0; // write compressed geometries for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) { - const std::vector & current_vector = m_compressed_geometries[i]; + const std::vector & current_vector = m_compressed_geometries[i]; const unsigned unpacked_size = current_vector.size(); + control_sum += unpacked_size; BOOST_ASSERT( UINT_MAX != unpacked_size ); - for(unsigned j = 0; j < unpacked_size; ++j) { + BOOST_FOREACH(const CompressedNode current_node, current_vector ) { geometry_out_stream.write( - (char*)&(current_vector[j]), - sizeof(unsigned) + (char*)&(current_node.first), + sizeof(NodeID) ); } } - + BOOST_ASSERT( control_sum == prefix_sum_of_list_indices ); // all done, let's close the resource geometry_out_stream.close(); } @@ -118,8 +141,11 @@ void GeometryCompressor::SerializeInternalVector( void GeometryCompressor::CompressEdge( const EdgeID surviving_edge_id, const EdgeID removed_edge_id, - const NodeID via_node_id + const NodeID via_node_id, + const EdgeWeight weight1//, + // const EdgeWeight weight2 ) { + BOOST_ASSERT( UINT_MAX != surviving_edge_id ); BOOST_ASSERT( UINT_MAX != removed_edge_id ); BOOST_ASSERT( UINT_MAX != via_node_id ); @@ -138,60 +164,80 @@ void GeometryCompressor::CompressEdge( // create a new entry in the map if( 0 == m_free_list.size() ) { // make sure there is a place to put the entries + // SimpleLogger().Write() << "increased free list"; IncreaseFreeList(); } + BOOST_ASSERT( !m_free_list.empty() ); + // SimpleLogger().Write() << "free list size: " << m_free_list.size(); m_edge_id_to_list_index_map[surviving_edge_id] = m_free_list.back(); m_free_list.pop_back(); } const unsigned surving_list_id = m_edge_id_to_list_index_map[surviving_edge_id]; + BOOST_ASSERT( surving_list_id == GetPositionForID(surviving_edge_id)); + + // SimpleLogger().Write() << "surviving edge id " << surviving_edge_id << " is listed at " << surving_list_id; BOOST_ASSERT( surving_list_id < m_compressed_geometries.size() ); - std::vector & compressed_id_list = m_compressed_geometries[surving_list_id]; - compressed_id_list.push_back(via_node_id); - BOOST_ASSERT( 0 < compressed_id_list.size() ); + std::vector & surviving_geometry_list = m_compressed_geometries[surving_list_id]; + if( !surviving_geometry_list.empty() ) { + BOOST_ASSERT( via_node_id != surviving_geometry_list.back().first ); + } + surviving_geometry_list.push_back( std::make_pair(via_node_id, weight1) ); + BOOST_ASSERT( 0 < surviving_geometry_list.size() ); + BOOST_ASSERT( !surviving_geometry_list.empty() ); // Find any existing list for removed_edge_id - typename boost::unordered_map::const_iterator map_iterator; - map_iterator = m_edge_id_to_list_index_map.find(removed_edge_id); - if( m_edge_id_to_list_index_map.end() != map_iterator ) { - const unsigned index = map_iterator->second; - BOOST_ASSERT( index < m_compressed_geometries.size() ); + typename boost::unordered_map::const_iterator remove_list_iterator; + remove_list_iterator = m_edge_id_to_list_index_map.find(removed_edge_id); + if( m_edge_id_to_list_index_map.end() != remove_list_iterator ) { + const unsigned list_to_remove_index = remove_list_iterator->second; + BOOST_ASSERT( list_to_remove_index == GetPositionForID(removed_edge_id)); + BOOST_ASSERT( list_to_remove_index < m_compressed_geometries.size() ); + + std::vector & remove_geometry_list = m_compressed_geometries[list_to_remove_index]; // found an existing list, append it to the list of surviving_edge_id - compressed_id_list.insert( - compressed_id_list.end(), - m_compressed_geometries[index].begin(), - m_compressed_geometries[index].end() + surviving_geometry_list.insert( + surviving_geometry_list.end(), + remove_geometry_list.begin(), + remove_geometry_list.end() ); //remove the list of removed_edge_id - m_edge_id_to_list_index_map.erase(map_iterator); + m_edge_id_to_list_index_map.erase(remove_list_iterator); BOOST_ASSERT( m_edge_id_to_list_index_map.end() == m_edge_id_to_list_index_map.find(removed_edge_id) ); - m_compressed_geometries[index].clear(); - BOOST_ASSERT( 0 == m_compressed_geometries[index].size() ); - m_free_list.push_back(index); - BOOST_ASSERT( index == m_free_list.back() ); + remove_geometry_list.clear(); + BOOST_ASSERT( 0 == remove_geometry_list.size() ); + m_free_list.push_back(list_to_remove_index); + BOOST_ASSERT( list_to_remove_index == m_free_list.back() ); } } void GeometryCompressor::PrintStatistics() const { - unsigned removed_edge_count = 0; - const unsigned surviving_edge_count = m_compressed_geometries.size()-m_free_list.size(); + unsigned number_of_compressed_geometries = 0; + const unsigned compressed_edges = m_compressed_geometries.size(); BOOST_ASSERT( m_compressed_geometries.size() + m_free_list.size() > 0 ); unsigned long longest_chain_length = 0; - BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) { - removed_edge_count += current_vector.size(); + BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) { + number_of_compressed_geometries += current_vector.size(); longest_chain_length = std::max(longest_chain_length, current_vector.size()); } - BOOST_ASSERT(0 == surviving_edge_count % 2); + BOOST_ASSERT(0 == compressed_edges % 2); SimpleLogger().Write() << - "surviving edges: " << surviving_edge_count << - ", compressed edges: " << removed_edge_count << + "compressed edges: " << compressed_edges << + ", compressed geometries: " << number_of_compressed_geometries << ", longest chain length: " << longest_chain_length << - ", comp ratio: " << ((float)surviving_edge_count/std::max(removed_edge_count, 1u) ) << - ", avg: chain length: " << (float)removed_edge_count/std::max(1u, surviving_edge_count); + ", cmpr ratio: " << ((float)compressed_edges/std::max(number_of_compressed_geometries, 1u) ) << + ", avg chain length: " << (float)number_of_compressed_geometries/std::max(1u, compressed_edges); SimpleLogger().Write() << - "No bytes: " << 4*surviving_edge_count + removed_edge_count*4; + "No bytes: " << 4*compressed_edges + number_of_compressed_geometries*4 +8; +} + +const std::vector & GeometryCompressor::GetBucketReference( + const EdgeID edge_id +) const { + const unsigned index = m_edge_id_to_list_index_map.at( edge_id ); + return m_compressed_geometries.at( index ); } diff --git a/Contractor/GeometryCompressor.h b/Contractor/GeometryCompressor.h index 1fda18cdb..1d2d60ea2 100644 --- a/Contractor/GeometryCompressor.h +++ b/Contractor/GeometryCompressor.h @@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../typedefs.h" #include +#include #include #include @@ -37,23 +38,31 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class GeometryCompressor { public: + typedef std::pair CompressedNode; + GeometryCompressor(); void CompressEdge( const EdgeID first_edge_id, const EdgeID second_edge_id, - const NodeID via_node_id + const NodeID via_node_id, + const EdgeWeight weight1//, + // const EdgeWeight weight2 ); + + void AddLastViaNodeIDToCompressedEdge( + const EdgeID edge_id, + const NodeID node_id, + const EdgeWeight weight + ); + bool HasEntryForID(const EdgeID edge_id) const; void PrintStatistics() const; - bool HasEntryForID(const EdgeID edge_id); - void AddNodeIDToCompressedEdge(const EdgeID edge_id, const NodeID node_id); - unsigned GetPositionForID(const EdgeID edge_id); void SerializeInternalVector(const std::string & path) const; + unsigned GetPositionForID(const EdgeID edge_id) const; + const std::vector & GetBucketReference(const EdgeID edge_id) const; private: - void IncreaseFreeList(); - - std::vector > m_compressed_geometries; + std::vector > m_compressed_geometries; std::vector m_free_list; boost::unordered_map m_edge_id_to_list_index_map; }; diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index 895baa8dd..6b562ba4b 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -1,28 +1,58 @@ #ifndef EDGE_BASED_NODE_H #define EDGE_BASED_NODE_H -#include - -#include - #include "../Util/MercatorUtil.h" #include "../typedefs.h" #include // An EdgeBasedNode represents a node in the edge-expanded graph. + +#include + 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) + reverse_edge_based_node_id(std::numeric_limits::max()), + lat1(std::numeric_limits::max()), + lon1(std::numeric_limits::max()), + lat2(std::numeric_limits::max()), + lon2(std::numeric_limits::max() >> 1), + belongsToTinyComponent(false), + 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) + { } + + EdgeBasedNode( + NodeID forward_edge_based_node_id, + NodeID reverse_edge_based_node_id, + int lat1, + int lon1, + int lat2, + int lon2, + bool belongsToTinyComponent, + NodeID name_id, + int forward_weight, + int reverse_weight, + int forward_offset_to_edge_based_node, + int reverse_offset_to_edge_based_node + ) : + forward_edge_based_node_id(forward_edge_based_node_id), + reverse_edge_based_node_id(reverse_edge_based_node_id), + lat1(lat1), + lon1(lon1), + lat2(lat2), + lon2(lon2), + belongsToTinyComponent(belongsToTinyComponent), + 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) { } // Computes: @@ -39,9 +69,26 @@ struct EdgeBasedNode { BOOST_ASSERT( query_location.isValid() ); const double epsilon = 1.0/precision; + const double y = query_location.lon/COORDINATE_PRECISION; + const double a = lat2y(lat1/COORDINATE_PRECISION); + const double b = lon1/COORDINATE_PRECISION; + const double c = lat2y(lat2/COORDINATE_PRECISION); + const double d = lon2/COORDINATE_PRECISION; + double p,q/*,mX*/,nY; + if( std::abs(a-c) > std::numeric_limits::epsilon() ){ + const double m = (d-b)/(c-a); // slope + // Projection of (x,y) on line joining (a,b) and (c,d) + p = ((x + (m*y)) + (m*m*a - m*b))/(1. + m*m); + q = b + m*(p - a); + } else { + p = c; + q = y; + } + nY = (d*p - c*q)/(a*d - b*c); - if( ignoreInGrid ) { - return std::numeric_limits::max(); + //discretize the result to coordinate precision. it's a hack! + if( std::abs(nY) < (1./COORDINATE_PRECISION) ) { + nY = 0.; } // p, q : the end points of the underlying edge @@ -50,13 +97,14 @@ struct EdgeBasedNode { // r : query location const Point r(lat2y(query_location.lat/COORDINATE_PRECISION), + } else if( std::abs(r-1.) <= std::numeric_limits::epsilon() ) { query_location.lon/COORDINATE_PRECISION); const Point foot = ComputePerpendicularFoot(p, q, r, epsilon); ratio = ComputeRatio(p, q, foot, epsilon); BOOST_ASSERT( !std::isnan(ratio) ); - + nearest_location.lat = y2lat(p)*COORDINATE_PRECISION; nearest_location = ComputeNearestPointOnSegment(foot, ratio); BOOST_ASSERT( nearest_location.isValid() ); @@ -65,6 +113,9 @@ struct EdgeBasedNode { // const double approximated_distance = FixedPointCoordinate::ApproximateEuclideanDistance( const double approximated_distance = FixedPointCoordinate::ApproximateDistance(query_location, nearest_location); + query_location, + nearest_location + ); BOOST_ASSERT( 0.0 <= approximated_distance ); return approximated_distance; } @@ -82,21 +133,21 @@ struct EdgeBasedNode { return FixedPointCoordinate((lat1+lat2)/2, (lon1+lon2)/2); } - NodeID id; + NodeID forward_edge_based_node_id; // The coordinates of the end-points of the underlying edge. int lat1; - int lat2; int lon1; + int lat2; int lon2:31; bool belongsToTinyComponent:1; - NodeID nameID; + NodeID name_id; // The weight of the underlying edge. unsigned weight:31; - bool ignoreInGrid:1; + int reverse_weight; private: diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 33e52cc12..880e1e707 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -162,7 +162,7 @@ public: m_weight(w), m_forward(f), m_backward(b) - {} + { } NodeID target() const { return m_target; } NodeID source() const { return m_source; } diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 3a3fbbd93..893586d62 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -29,37 +29,45 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define PHANTOMNODES_H_ #include - #include "../typedefs.h" struct PhantomNode { PhantomNode() : - edgeBasedNode(UINT_MAX), - nodeBasedEdgeNameID(UINT_MAX), - weight1(INT_MAX), - weight2(INT_MAX), + forward_node_id(UINT_MAX), + reverse_node_id(UINT_MAX), + name_id(UINT_MAX), + forward_weight(INT_MAX), + reverse_weight(INT_MAX), ratio(0.) { } - NodeID edgeBasedNode; - unsigned nodeBasedEdgeNameID; - int weight1; - int weight2; + NodeID forward_node_id; + NodeID reverse_node_id; + unsigned name_id; + int forward_weight; + int reverse_weight; double ratio; FixedPointCoordinate location; + void Reset() { - edgeBasedNode = UINT_MAX; - nodeBasedEdgeNameID = UINT_MAX; - weight1 = INT_MAX; - weight2 = INT_MAX; + forward_node_id = UINT_MAX; + name_id = UINT_MAX; + forward_weight = INT_MAX; + reverse_weight = INT_MAX; ratio = 0.; location.Reset(); } bool isBidirected() const { - return weight2 != INT_MAX; + return forward_weight != INT_MAX && reverse_weight != INT_MAX; } bool isValid(const unsigned numberOfNodes) const { - return location.isValid() && (edgeBasedNode < numberOfNodes) && (weight1 != INT_MAX) && (ratio >= 0.) && (ratio <= 1.) && (nodeBasedEdgeNameID != UINT_MAX); + return + location.isValid() && + ( (forward_node_id < numberOfNodes) || (reverse_node_id < numberOfNodes) ) && + ( (forward_weight != INT_MAX) || (reverse_weight != INT_MAX) ) && + (ratio >= 0.) && + (ratio <= 1.) && + (name_id != UINT_MAX); } bool operator==(const PhantomNode & other) const { @@ -76,11 +84,11 @@ struct PhantomNodes { } bool PhantomsAreOnSameNodeBasedEdge() const { - return (startPhantom.edgeBasedNode == targetPhantom.edgeBasedNode); + return (startPhantom.forward_node_id == targetPhantom.forward_node_id); } bool AtLeastOnePhantomNodeIsUINTMAX() const { - return !(startPhantom.edgeBasedNode == UINT_MAX || targetPhantom.edgeBasedNode == UINT_MAX); + return !(startPhantom.forward_node_id == UINT_MAX || targetPhantom.forward_node_id == UINT_MAX); } bool PhantomNodesHaveEqualLocation() const { @@ -89,15 +97,15 @@ struct PhantomNodes { }; inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){ - out << "Node1: " << pn.startPhantom.edgeBasedNode << std::endl; - out << "Node2: " << pn.targetPhantom.edgeBasedNode << std::endl; - out << "startCoord: " << pn.startPhantom.location << std::endl; + out << "Node1: " << pn.startPhantom.forward_node_id << std::endl; + out << "Node2: " << pn.targetPhantom.reverse_node_id << std::endl; + out << "startCoord: " << pn.startPhantom.location << std::endl; out << "targetCoord: " << pn.targetPhantom.location << std::endl; return out; } inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn){ - out << "node: " << pn.edgeBasedNode << ", name: " << pn.nodeBasedEdgeNameID << ", w1: " << pn.weight1 << ", w2: " << pn.weight2 << ", ratio: " << pn.ratio << ", loc: " << pn.location; + out << "node1: " << pn.forward_node_id << ", node2: " << pn.reverse_node_id << ", name: " << pn.name_id << ", w1: " << pn.forward_weight << ", w2: " << pn.reverse_weight << ", ratio: " << pn.ratio << ", loc: " << pn.location; return out; } diff --git a/DataStructures/QueryNode.h b/DataStructures/QueryNode.h index ae0dc4bac..22a440415 100644 --- a/DataStructures/QueryNode.h +++ b/DataStructures/QueryNode.h @@ -34,17 +34,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include -#include - #include struct NodeInfo { typedef NodeID key_type; //type of NodeID typedef int value_type; //type of lat,lons - NodeInfo(int _lat, int _lon, NodeID _id) : lat(_lat), lon(_lon), id(_id) {} - NodeInfo() : lat(INT_MAX), lon(INT_MAX), id(UINT_MAX) {} + NodeInfo(int lat, int lon, NodeID id) : lat(lat), lon(lon), id(id) { } + NodeInfo() + : + lat(std::numeric_limits::max()), + lon(std::numeric_limits::max()), + id(std::numeric_limits::max()) + { } + int lat; int lon; NodeID id; @@ -75,11 +78,11 @@ struct NodeInfo { break; default: BOOST_ASSERT_MSG(false, "should not happen"); - return UINT_MAX; + return std::numeric_limits::max(); break; } BOOST_ASSERT_MSG(false, "should not happen"); - return UINT_MAX; + return std::numeric_limits::max(); } }; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 059a9b0ef..da5821c08 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -487,152 +487,7 @@ public: //SimpleLogger().Write() << m_element_count << " elements in leafs"; } //Read-only operation for queries -/* - inline void FindKNearestPhantomNodesForCoordinate( - const FixedPointCoordinate & location, - const unsigned zoom_level, - const unsigned candidate_count, - std::vector > & result_vector - ) const { - bool ignore_tiny_components = (zoom_level <= 14); - DataT nearest_edge; - - uint32_t io_count = 0; - uint32_t explored_tree_nodes_count = 0; - SimpleLogger().Write() << "searching for coordinate " << input_coordinate; - double min_dist = std::numeric_limits::max(); - double min_max_dist = std::numeric_limits::max(); - bool found_a_nearest_edge = false; - - FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate; - - //initialize queue with root element - std::priority_queue traversal_queue; - traversal_queue.push(QueryCandidate(0, m_search_tree[0].minimum_bounding_rectangle.GetMinDist(input_coordinate))); - BOOST_ASSERT_MSG(std::numberic_limits::epsilon() > (0. - traversal_queue.top().min_dist), "Root element in NN Search has min dist != 0."); - - while(!traversal_queue.empty()) { - const QueryCandidate current_query_node = traversal_queue.top(); traversal_queue.pop(); - - ++explored_tree_nodes_count; - bool prune_downward = (current_query_node.min_dist >= min_max_dist); - bool prune_upward = (current_query_node.min_dist >= min_dist); - if( !prune_downward && !prune_upward ) { //downward pruning - TreeNode & current_tree_node = m_search_tree[current_query_node.node_id]; - if (current_tree_node.child_is_on_disk) { - LeafNode current_leaf_node; - LoadLeafFromDisk(current_tree_node.children[0], current_leaf_node); - ++io_count; - for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) { - DataT & current_edge = current_leaf_node.objects[i]; - if(ignore_tiny_components && current_edge.belongsToTinyComponent) { - continue; - } - - double current_ratio = 0.; - double current_perpendicular_distance = current_edge.ComputePerpendicularDistance( - input_coordinate, - nearest, - current_ratio - ); - - if( - current_perpendicular_distance < min_dist - && !DoubleEpsilonCompare( - current_perpendicular_distance, - min_dist - ) - ) { //found a new minimum - min_dist = current_perpendicular_distance; - result_phantom_node.edgeBasedNode = current_edge.id; - result_phantom_node.nodeBasedEdgeNameID = current_edge.nameID; - result_phantom_node.weight1 = current_edge.weight; - result_phantom_node.weight2 = INT_MAX; - result_phantom_node.location = nearest; - current_start_coordinate.lat = current_edge.lat1; - current_start_coordinate.lon = current_edge.lon1; - current_end_coordinate.lat = current_edge.lat2; - current_end_coordinate.lon = current_edge.lon2; - nearest_edge = current_edge; - found_a_nearest_edge = true; - } else if( - DoubleEpsilonCompare(current_perpendicular_distance, min_dist) && - 1 == abs(current_edge.id - result_phantom_node.edgeBasedNode ) - && EdgesAreEquivalent( - current_start_coordinate, - FixedPointCoordinate( - current_edge.lat1, - current_edge.lon1 - ), - FixedPointCoordinate( - current_edge.lat2, - current_edge.lon2 - ), - current_end_coordinate - ) - ) { - result_phantom_node.edgeBasedNode = std::min(current_edge.id, result_phantom_node.edgeBasedNode); - result_phantom_node.weight2 = current_edge.weight; - } - } - } else { - //traverse children, prune if global mindist is smaller than local one - for (uint32_t i = 0; i < current_tree_node.child_count; ++i) { - const int32_t child_id = current_tree_node.children[i]; - TreeNode & child_tree_node = m_search_tree[child_id]; - RectangleT & child_rectangle = child_tree_node.minimum_bounding_rectangle; - const double current_min_dist = child_rectangle.GetMinDist(input_coordinate); - const double current_min_max_dist = child_rectangle.GetMinMaxDist(input_coordinate); - if( current_min_max_dist < min_max_dist ) { - min_max_dist = current_min_max_dist; - } - if (current_min_dist > min_max_dist) { - continue; - } - if (current_min_dist > min_dist) { //upward pruning - continue; - } - traversal_queue.push(QueryCandidate(child_id, current_min_dist)); - } - } - } - } - - const double distance_to_edge = - ApproximateDistance ( - FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1), - result_phantom_node.location - ); - - const double length_of_edge = - ApproximateDistance( - FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1), - FixedPointCoordinate(nearest_edge.lat2, nearest_edge.lon2) - ); - - const double ratio = (found_a_nearest_edge ? - std::min(1., distance_to_edge/ length_of_edge ) : 0 ); - result_phantom_node.weight1 *= ratio; - if(INT_MAX != result_phantom_node.weight2) { - result_phantom_node.weight2 *= (1.-ratio); - } - result_phantom_node.ratio = ratio; - - //Hack to fix rounding errors and wandering via nodes. - if(std::abs(input_coordinate.lon - result_phantom_node.location.lon) == 1) { - result_phantom_node.location.lon = input_coordinate.lon; - } - if(std::abs(input_coordinate.lat - result_phantom_node.location.lat) == 1) { - result_phantom_node.location.lat = input_coordinate.lat; - } - - SimpleLogger().Write() << "mindist: " << min_distphantom_node.isBidirected() ? "yes" : "no"); - return found_a_nearest_edge; - - } - - */ bool LocateClosestEndPointForCoordinate( const FixedPointCoordinate & input_coordinate, FixedPointCoordinate & result_coordinate, @@ -799,10 +654,11 @@ public: ) ) { //found a new minimum min_dist = current_perpendicular_distance; - result_phantom_node.edgeBasedNode = current_edge.id; - result_phantom_node.nodeBasedEdgeNameID = current_edge.nameID; - result_phantom_node.weight1 = current_edge.weight; - result_phantom_node.weight2 = INT_MAX; + result_phantom_node.forward_node_id = current_edge.forward_edge_based_node_id; + result_phantom_node.reverse_node_id = current_edge.reverse_edge_based_node_id; + 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.location = nearest; current_start_coordinate.lat = current_edge.lat1; current_start_coordinate.lon = current_edge.lon1; @@ -810,30 +666,6 @@ public: current_end_coordinate.lon = current_edge.lon2; nearest_edge = current_edge; found_a_nearest_edge = true; - } else - if( DoubleEpsilonCompare(current_perpendicular_distance, min_dist) && - ( 1 == abs(current_edge.id - result_phantom_node.edgeBasedNode ) ) && - EdgesAreEquivalent( - current_start_coordinate, - FixedPointCoordinate( - current_edge.lat1, - current_edge.lon1 - ), - FixedPointCoordinate( - current_edge.lat2, - current_edge.lon2 - ), - current_end_coordinate - ) - ) { - - BOOST_ASSERT_MSG(current_edge.id != result_phantom_node.edgeBasedNode, "IDs not different"); - result_phantom_node.weight2 = current_edge.weight; - if(current_edge.id < result_phantom_node.edgeBasedNode) { - result_phantom_node.edgeBasedNode = current_edge.id; - std::swap(result_phantom_node.weight1, result_phantom_node.weight2); - std::swap(current_end_coordinate, current_start_coordinate); - } } } } else { @@ -884,9 +716,9 @@ public: ratio = std::min(1., ratio); } - result_phantom_node.weight1 *= ratio; - if(INT_MAX != result_phantom_node.weight2) { - result_phantom_node.weight2 *= (1.-ratio); + result_phantom_node.forward_weight *= ratio; + if( INT_MAX != result_phantom_node.reverse_weight ) { + result_phantom_node.reverse_weight *= (1.-ratio); } result_phantom_node.ratio = ratio; diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 90b57d2b3..dacb60a60 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -64,7 +64,7 @@ void DescriptionFactory::SetStartSegment(const PhantomNode & start) { start_phantom = start; AppendSegment( start.location, - PathData(0, start.nodeBasedEdgeNameID, 10, start.weight1) + PathData(0, start.name_id, 10, start.forward_weight) ); } @@ -73,9 +73,9 @@ void DescriptionFactory::SetEndSegment(const PhantomNode & target) { pathDescription.push_back( SegmentInformation( target.location, - target.nodeBasedEdgeNameID, + target.name_id, 0, - target.weight1, + target.reverse_weight, 0, true ) @@ -137,7 +137,7 @@ void DescriptionFactory::BuildRouteSummary( const double distance, const unsigned time ) { - summary.startName = start_phantom.nodeBasedEdgeNameID; - summary.destName = target_phantom.nodeBasedEdgeNameID; + summary.startName = start_phantom.name_id; + summary.destName = target_phantom.name_id; summary.BuildDurationAndLengthStrings(distance, time); } diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 53deca7f4..12d0213b2 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -180,7 +180,7 @@ public: pathDescription.pop_back(); pathDescription.back().necessary = true; pathDescription.back().turn_instruction = TurnInstructions.NoTurn; - target_phantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->name_id; + target_phantom.name_id = (pathDescription.end()-2)->name_id; } } else { pathDescription[indexOfSegmentBegin].duration *= (1.-target_phantom.ratio); @@ -190,7 +190,7 @@ public: pathDescription.erase(pathDescription.begin()); pathDescription[0].turn_instruction = TurnInstructions.HeadOn; pathDescription[0].necessary = true; - start_phantom.nodeBasedEdgeNameID = pathDescription[0].name_id; + start_phantom.name_id = pathDescription[0].name_id; } } else { pathDescription[0].duration *= start_phantom.ratio; diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 80a410e1e..1f5389727 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -112,28 +112,28 @@ public: int upper_bound_to_shortest_path_distance = INT_MAX; NodeID middle_node = UINT_MAX; forward_heap1.Insert( - phantom_node_pair.startPhantom.edgeBasedNode, - -phantom_node_pair.startPhantom.weight1, - phantom_node_pair.startPhantom.edgeBasedNode + phantom_node_pair.startPhantom.forward_node_id, + -phantom_node_pair.startPhantom.forward_weight, + phantom_node_pair.startPhantom.forward_node_id ); 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 + phantom_node_pair.startPhantom.reverse_node_id, + -phantom_node_pair.startPhantom.reverse_weight, + phantom_node_pair.startPhantom.reverse_node_id ); } reverse_heap1.Insert( - phantom_node_pair.targetPhantom.edgeBasedNode, - phantom_node_pair.targetPhantom.weight1, - phantom_node_pair.targetPhantom.edgeBasedNode + phantom_node_pair.targetPhantom.forward_node_id, + phantom_node_pair.targetPhantom.forward_weight, + phantom_node_pair.targetPhantom.forward_node_id ); 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 + phantom_node_pair.targetPhantom.reverse_node_id, + phantom_node_pair.targetPhantom.reverse_weight, + phantom_node_pair.targetPhantom.reverse_node_id ); } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 00bb2e167..fa495d583 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -30,10 +30,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../DataStructures/RawRouteData.h" #include "../DataStructures/SearchEngineData.h" +#include "../DataStructures/TurnInstructions.h" #include "../Util/ContainerUtils.h" #include "../Util/SimpleLogger.h" #include +#include #include #include @@ -188,7 +190,7 @@ public: } } } - BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); + BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid"); const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if( ed.shortcut ) {//unpack @@ -197,15 +199,43 @@ public: 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"); - unpacked_path.push_back( - PathData( - ed.id, - facade->GetNameIndexFromEdgeID(ed.id), - facade->GetTurnInstructionForEdgeID(ed.id), - ed.distance - ) - ); + 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 + 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) ); + unpacked_path.push_back( + PathData( + facade->GetGeometryIndexForEdgeID(ed.id), + name_index, + turn_instruction, + ed.distance + ) + ); + } else { + 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 + + unpacked_path.push_back( + PathData( + coordinate_id, + name_index, + TurnInstructionsClass::NoTurn, + 0 + ) + ); + + } + unpacked_path.back().turnInstruction = turn_instruction; + unpacked_path.back().durationOfSegment = ed.distance; + } + } } } @@ -313,7 +343,7 @@ public: } int ComputeEdgeOffset(const PhantomNode & phantom) const { - return phantom.weight1 + (phantom.isBidirected() ? phantom.weight2 : 0); + return phantom.forward_weight + (phantom.isBidirected() ? phantom.reverse_weight : 0); } }; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 982b7b13d..4cd7f9bab 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -105,41 +105,47 @@ public: //insert new starting nodes into forward heap, adjusted by previous distances. if(search_from_1st_node) { + BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX); + forward_heap1.Insert( - phantom_node_pair.startPhantom.edgeBasedNode, - distance1-phantom_node_pair.startPhantom.weight1, - phantom_node_pair.startPhantom.edgeBasedNode + phantom_node_pair.startPhantom.forward_node_id, + distance1-phantom_node_pair.startPhantom.forward_weight, + phantom_node_pair.startPhantom.forward_node_id ); forward_heap2.Insert( - phantom_node_pair.startPhantom.edgeBasedNode, - distance1-phantom_node_pair.startPhantom.weight1, - phantom_node_pair.startPhantom.edgeBasedNode + phantom_node_pair.startPhantom.forward_node_id, + distance1-phantom_node_pair.startPhantom.forward_weight, + phantom_node_pair.startPhantom.forward_node_id ); } if(phantom_node_pair.startPhantom.isBidirected() && search_from_2nd_node) { + BOOST_ASSERT(phantom_node_pair.startPhantom.reverse_node_id != UINT_MAX); forward_heap1.Insert( - phantom_node_pair.startPhantom.edgeBasedNode+1, - distance2-phantom_node_pair.startPhantom.weight2, - phantom_node_pair.startPhantom.edgeBasedNode+1 + phantom_node_pair.startPhantom.reverse_node_id, + distance2-phantom_node_pair.startPhantom.reverse_weight, + phantom_node_pair.startPhantom.reverse_node_id ); forward_heap2.Insert( - phantom_node_pair.startPhantom.edgeBasedNode+1, - distance2-phantom_node_pair.startPhantom.weight2, - phantom_node_pair.startPhantom.edgeBasedNode+1 + phantom_node_pair.startPhantom.reverse_node_id, + distance2-phantom_node_pair.startPhantom.reverse_weight, + phantom_node_pair.startPhantom.reverse_node_id ); } //insert new backward nodes into backward heap, unadjusted. reverse_heap1.Insert( - phantom_node_pair.targetPhantom.edgeBasedNode, - phantom_node_pair.targetPhantom.weight1, - phantom_node_pair.targetPhantom.edgeBasedNode + phantom_node_pair.targetPhantom.forward_node_id, + phantom_node_pair.targetPhantom.forward_weight, + phantom_node_pair.targetPhantom.forward_node_id ); + BOOST_ASSERT(phantom_node_pair.targetPhantom.forward_node_id != UINT_MAX); + if(phantom_node_pair.targetPhantom.isBidirected() ) { + BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX); reverse_heap2.Insert( - phantom_node_pair.targetPhantom.edgeBasedNode+1, - phantom_node_pair.targetPhantom.weight2, - phantom_node_pair.targetPhantom.edgeBasedNode+1 + phantom_node_pair.targetPhantom.reverse_node_id, + phantom_node_pair.targetPhantom.reverse_weight, + phantom_node_pair.targetPhantom.reverse_node_id ); } @@ -264,8 +270,6 @@ public: local_upper_bound2 = local_upper_bound1; } - // SimpleLogger().Write() << "fetched packed paths"; - BOOST_ASSERT_MSG( !temporary_packed_leg1.empty() || !temporary_packed_leg2.empty(), @@ -338,8 +342,8 @@ public: phantom_node_pair.targetPhantom.isBidirected() ) { const NodeID last_node_id = packed_legs2[current_leg].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); + search_from_1st_node &= !(last_node_id == phantom_node_pair.targetPhantom.reverse_node_id); + search_from_2nd_node &= !(last_node_id == phantom_node_pair.targetPhantom.forward_node_id); BOOST_ASSERT( search_from_1st_node != search_from_2nd_node ); } diff --git a/Server/DataStructures/BaseDataFacade.h b/Server/DataStructures/BaseDataFacade.h index 6c4726a9c..7b7a73762 100644 --- a/Server/DataStructures/BaseDataFacade.h +++ b/Server/DataStructures/BaseDataFacade.h @@ -86,6 +86,15 @@ public: const unsigned id ) const = 0; + virtual bool EdgeIsCompressed( const unsigned id ) const = 0; + + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const = 0; + + virtual void GetUncompressedGeometry( + const unsigned id, + std::vector & result_nodes + ) const = 0; + virtual TurnInstruction GetTurnInstructionForEdgeID( const unsigned id ) const = 0; diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 249c37bda..93cf39811 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -67,6 +67,9 @@ private: ShM::vector m_turn_instruction_list; ShM::vector m_names_char_list; ShM::vector m_name_begin_indices; + ShM::vector m_egde_is_compressed; + ShM::vector m_compressed_geometry_indices; + ShM::vector m_compressed_geometries; StaticRTree * m_static_rtree; @@ -146,9 +149,12 @@ private: ); 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_via_node_list.resize (number_of_edges); + m_name_ID_list.resize (number_of_edges); m_turn_instruction_list.resize(number_of_edges); + m_egde_is_compressed.resize (number_of_edges); + + unsigned compressed = 0; OriginalEdgeData current_edge_data; for(unsigned i = 0; i < number_of_edges; ++i) { @@ -157,16 +163,58 @@ private: sizeof(OriginalEdgeData) ); m_via_node_list[i] = current_edge_data.via_node; + if(current_edge_data.via_node == 0 && current_edge_data.compressed_geometry) { + SimpleLogger().Write() << "0 at index " << i; + } + m_name_ID_list[i] = current_edge_data.name_id; m_turn_instruction_list[i] = current_edge_data.turn_instruction; + m_egde_is_compressed[i] = current_edge_data.compressed_geometry; + if(m_egde_is_compressed[i]) { + ++compressed; + } } + SimpleLogger().Write(logDEBUG) << "compressed: " << compressed; + edges_input_stream.close(); } void LoadGeometries( - const boost::filesystem::path & geometries_file + const boost::filesystem::path & geometry_file ) { + std::ifstream geometry_stream( + geometry_file.c_str(), + std::ios::binary + ); + unsigned number_of_indices = 0; + unsigned number_of_compressed_geometries = 0; + geometry_stream.read( + (char *)&number_of_indices, + sizeof(unsigned) + ); + m_compressed_geometry_indices.resize(number_of_indices); + geometry_stream.read( + (char *)&(m_compressed_geometry_indices[0]), + number_of_indices*sizeof(unsigned) + ); + + geometry_stream.read( + (char *)&number_of_compressed_geometries, + sizeof(unsigned) + ); + + BOOST_ASSERT( m_compressed_geometry_indices.back() == number_of_compressed_geometries ); + m_compressed_geometries.resize( number_of_compressed_geometries ); + + geometry_stream.read( + (char *)&(m_compressed_geometries[0]), + number_of_compressed_geometries*sizeof(unsigned) + ); + geometry_stream.close(); + + SimpleLogger().Write() << "number_of_indices: " << number_of_indices; + SimpleLogger().Write() << "number_of_compressed_geometries: " << number_of_compressed_geometries; } void LoadRTree( @@ -330,10 +378,15 @@ public: FixedPointCoordinate GetCoordinateOfNode( const unsigned id ) const { - const NodeID node = m_via_node_list.at(id); - return m_coordinate_list.at(node); + // const unsigned coordinate_index = m_via_node_list.at(id); + return m_coordinate_list.at(id); }; + bool EdgeIsCompressed( const unsigned id ) const { + // const NodeID node = m_via_node_list.at(id); + return m_egde_is_compressed.at(id); + } + TurnInstruction GetTurnInstructionForEdgeID( const unsigned id ) const { @@ -400,6 +453,29 @@ public: ); } + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const { + return m_via_node_list.at(id); + } + + virtual void GetUncompressedGeometry( + const unsigned id, std::vector & result_nodes + ) const { + const NodeID node = m_via_node_list.at(id); + SimpleLogger().Write() << "translated " << id << " to " << node; + SimpleLogger().Write() << "getting geometry from compression bucket " << node << "/" << m_compressed_geometry_indices.size(); + unsigned begin = m_compressed_geometry_indices.at(node); + unsigned end = m_compressed_geometry_indices.at(node+1); + SimpleLogger().Write() << "bucket " << node << " has range [" << begin << "," << end-1 << "]"; + //TODO: use vector.insert(.) + for(unsigned geometry_index = begin; geometry_index < end; ++geometry_index) { + 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); + } + } + + std::string GetTimestamp() const { return m_timestamp; } diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 213b696a2..461220d08 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -308,10 +308,25 @@ public: FixedPointCoordinate GetCoordinateOfNode( const unsigned id ) const { - const NodeID node = m_via_node_list.at(id); - return m_coordinate_list.at(node); + // const NodeID node = m_via_node_list.at(id); + return m_coordinate_list.at(id); }; + virtual bool EdgeIsCompressed( const unsigned id ) const { + //TODO!! + return false; + } + + virtual void GetUncompressedGeometry( + const unsigned id, std::vector & result_nodes + ) const { + //TODO!! + } + + virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const { + return m_via_node_list.at(id); + } + TurnInstruction GetTurnInstructionForEdgeID( const unsigned id ) const { diff --git a/Util/ProgramOptions.h b/Util/ProgramOptions.h index 1b7fbc292..c1e453016 100644 --- a/Util/ProgramOptions.h +++ b/Util/ProgramOptions.h @@ -111,9 +111,9 @@ inline unsigned GenerateServerProgramOptions( boost::program_options::value(&paths["edgesdata"]), ".edges file") ( - "geometries", + "geometry", boost::program_options::value(&paths["geometries"]), - ".geometries file") + ".geometry file") ( "ramindex", boost::program_options::value(&paths["ramindex"]), @@ -256,6 +256,17 @@ inline unsigned GenerateServerProgramOptions( } + path_iterator = paths.find("geometries"); + if( + path_iterator != paths.end() && + !boost::filesystem::is_regular_file(path_iterator->second) + ) { + path_iterator->second = base_string + ".geometry"; + } else { + throw OSRMException(base_string + ".geometry not found"); + } + + path_iterator = paths.find("ramindex"); if( path_iterator != paths.end() && diff --git a/prepare.cpp b/prepare.cpp index 43130f0b7..c56b6a91f 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -259,7 +259,10 @@ int main (int argc, char *argv[]) { std::vector().swap(inputRestrictions); std::vector().swap(bollardNodes); std::vector().swap(trafficLightNodes); - NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); + unsigned edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfEdgeBasedNodes(); + BOOST_ASSERT( + edgeBasedNodeNumber != std::numeric_limits::max() + ); DeallocatingVector edgeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList); std::vector nodeBasedEdgeList; diff --git a/routed.cpp b/routed.cpp index bd5f46373..6b53ee740 100644 --- a/routed.cpp +++ b/routed.cpp @@ -108,6 +108,7 @@ int main (int argc, const char * argv[]) SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"]; SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"]; SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"]; + SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"]; SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"]; SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"]; SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"]; From d0349d9b0d0554073d9e67094477a66c2b2d4b5d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 17 Feb 2014 09:29:29 +0100 Subject: [PATCH 07/89] further copy edits --- Contractor/EdgeBasedGraphFactory.cpp | 1 + DataStructures/HashTable.h | 2 +- DataStructures/StaticRTree.h | 10 +++++----- Extractor/ScriptingEnvironment.cpp | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 27318b23b..0402eb174 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -303,6 +303,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { if( forward_geometry[i].first != reverse_geometry[reverse_geometry.size()-1-i].first ) { #ifndef NDEBUG + //Dumps debug information when data is borked SimpleLogger().Write() << "size1: " << forward_geometry.size() << ", size2: " << reverse_geometry.size(); SimpleLogger().Write() << "index1: " << i << ", index2: " << reverse_geometry.size()-1-i; SimpleLogger().Write() << forward_geometry[0].first << "!=" << reverse_geometry[reverse_geometry.size()-1-i].first; diff --git a/DataStructures/HashTable.h b/DataStructures/HashTable.h index b4984e4b5..871ba4933 100644 --- a/DataStructures/HashTable.h +++ b/DataStructures/HashTable.h @@ -54,7 +54,7 @@ public: return boost::cref(iter->second); } - inline bool Holds( KeyT const & key) const { + inline const bool Holds( KeyT const & key) const { if( super::find(key) == super::end() ) { return false; } diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index da5821c08..62aa2a056 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -82,7 +82,7 @@ public: int32_t min_lat, max_lat; inline void InitializeMBRectangle( - const DataT * objects, + DataT const * objects, const uint32_t element_count ) { for(uint32_t i = 0; i < element_count; ++i) { @@ -221,9 +221,9 @@ public: } inline bool Contains(const FixedPointCoordinate & location) const { - bool lats_contained = + const bool lats_contained = (location.lat > min_lat) && (location.lat < max_lat); - bool lons_contained = + const bool lons_contained = (location.lon > min_lon) && (location.lon < max_lon); return lats_contained && lons_contained; } @@ -315,7 +315,7 @@ public: for(uint64_t element_counter = 0; element_counter < m_element_count; ++element_counter) { input_wrapper_vector[element_counter].m_array_index = element_counter; //Get Hilbert-Value for centroid in mercartor projection - DataT & current_element = input_data_vector[element_counter]; + DataT const & current_element = input_data_vector[element_counter]; FixedPointCoordinate current_centroid = current_element.Centroid(); current_centroid.lat = COORDINATE_PRECISION*lat2y(current_centroid.lat/COORDINATE_PRECISION); @@ -526,7 +526,7 @@ public: current_leaf_node ); for(uint32_t i = 0; i < current_leaf_node.object_count; ++i) { - const DataT & current_edge = current_leaf_node.objects[i]; + DataT const & current_edge = current_leaf_node.objects[i]; if( ignore_tiny_components && current_edge.belongsToTinyComponent diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index d904b649a..c51ddd813 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -58,7 +58,7 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { // Add our function to the state's global scope luabind::module(myLuaState) [ luabind::def("print", LUA_print), - luabind::def("parseMaxspeed", parseMaxspeed), + // luabind::def("parseMaxspeed", parseMaxspeed), luabind::def("durationIsValid", durationIsValid), luabind::def("parseDuration", parseDuration) ]; @@ -66,7 +66,7 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { luabind::module(myLuaState) [ luabind::class_ >("keyVals") .def("Add", &HashTable::Add) - .def("Find", &HashTable::Find) + .def("Get", &HashTable::Get) .def("Holds", &HashTable::Holds) ]; From 149d0378244e2d9e2ee24710bc0595fe1f894b01 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 17 Feb 2014 09:30:31 +0100 Subject: [PATCH 08/89] further copy edits --- Plugins/NearestPlugin.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 0543dffe0..2484d0fac 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -50,10 +50,9 @@ public: descriptorTable.emplace("json", 1); } const std::string & GetDescriptor() const { return descriptor_string; } - void HandleRequest( const RouteParameters & routeParameters, - http::Reply& reply + http::Reply & reply ) { //check number of parameters if(!routeParameters.coordinates.size()) { @@ -82,13 +81,13 @@ public: reply.status = http::Reply::ok; reply.content.push_back("{\"status\":"); - if(UINT_MAX != result.edgeBasedNode) { + if(UINT_MAX != result.forward_node_id) { reply.content.push_back("0,"); } else { reply.content.push_back("207,"); } reply.content.push_back("\"mapped_coordinate\":["); - if(UINT_MAX != result.edgeBasedNode) { + if(UINT_MAX != result.forward_node_id) { FixedPointCoordinate::convertInternalLatLonToString(result.location.lat, temp_string); reply.content.push_back(temp_string); FixedPointCoordinate::convertInternalLatLonToString(result.location.lon, temp_string); @@ -96,8 +95,8 @@ public: reply.content.push_back(temp_string); } reply.content.push_back("],\"name\":\""); - if(UINT_MAX != result.edgeBasedNode) { - facade->GetName(result.nodeBasedEdgeNameID, temp_string); + if(UINT_MAX != result.forward_node_id) { + facade->GetName(result.name_id, temp_string); reply.content.push_back(temp_string); } reply.content.push_back("\"}"); From ba0b664e3f51a0b17dcc92897cdf0e47f63e7bb6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 17 Feb 2014 09:31:15 +0100 Subject: [PATCH 09/89] further copy edits --- profiles/car.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/profiles/car.lua b/profiles/car.lua index 05b8e7298..4a8564eb6 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -77,6 +77,14 @@ local function parse_maxspeed(source) return n end +-- function turn_function (angle) +-- -- print ("called at angle " .. angle ) +-- local index = math.abs(math.floor(angle/10+0.5))+1 -- +1 'coz LUA starts as idx 1 +-- local penalty = turn_cost_table[index] +-- -- print ("index: " .. index .. ", bias: " .. penalty ) +-- return penalty +-- end + function node_function (node) local access = find_access_tag(node, access_tags_hierachy) @@ -260,4 +268,4 @@ function node_vector_function(vector) for v in vector.nodes do node_function(v) end -end \ No newline at end of file +end From f7d5b0db9c3233acf38b7ec19bf150b5d644fefc Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 18 Feb 2014 19:26:57 +0100 Subject: [PATCH 10/89] uncompressed edges get serialized correctly'ish --- Contractor/EdgeBasedGraphFactory.cpp | 306 ++++++++++++++++++++------- Contractor/EdgeBasedGraphFactory.h | 1 + Contractor/GeometryCompressor.cpp | 26 ++- DataStructures/ImportEdge.h | 8 +- DataStructures/ImportNode.h | 10 +- DataStructures/PhantomNodes.h | 16 +- DataStructures/StaticRTree.h | 5 + Extractor/ExtractionContainers.cpp | 14 +- Extractor/ExtractorCallbacks.cpp | 49 +++-- Extractor/InternalExtractorEdge.h | 100 +++------ Extractor/ScriptingEnvironment.cpp | 2 +- Util/GraphLoader.h | 5 +- 12 files changed, 349 insertions(+), 193 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 0402eb174..81f27264c 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include EdgeBasedGraphFactory::EdgeBasedGraphFactory( int number_of_nodes, @@ -85,10 +86,15 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( traffic_light_node_list.end() ); - DeallocatingVector< NodeBasedEdge > edges_list; + std::sort( input_edge_list.begin(), input_edge_list.end() ); + + //TODO: remove duplicate edges + + DeallocatingVector edges_list; NodeBasedEdge edge; BOOST_FOREACH(const ImportEdge & import_edge, input_edge_list) { - if(!import_edge.isForward()) { + + if( !import_edge.isForward() ) { edge.source = import_edge.target(); edge.target = import_edge.source(); edge.data.backward = import_edge.isForward(); @@ -99,7 +105,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( edge.data.forward = import_edge.isForward(); edge.data.backward = import_edge.isBackward(); } - if(edge.source == edge.target) { + + if( edge.source == edge.target ) { continue; } @@ -114,9 +121,19 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( edge.data.contraFlow = import_edge.isContraFlow(); edges_list.push_back( edge ); - std::swap( edge.source, edge.target ); - edge.data.SwapDirectionFlags(); - edges_list.push_back( edge ); + if( !import_edge.IsSplit() ) { + using std::swap; //enable ADL + swap( edge.source, edge.target ); + edge.data.SwapDirectionFlags(); + edges_list.push_back( edge ); + } + + // if( import_edge.source() == 150903 || import_edge.target() == 150903 ) { + // SimpleLogger().Write(logDEBUG) << "[" << edges_list.size() << "] (" << import_edge.source() << "," << import_edge.target() << "), w: " << import_edge.weight(); + // if( import_edge.IsSplit() ) { + // SimpleLogger().Write(logDEBUG) << "edge split: (" << import_edge.source() << "," << import_edge.target() << ")"; + // } + // } } std::vector().swap(input_edge_list); @@ -267,31 +284,64 @@ bool EdgeBasedGraphFactory::CheckIfTurnIsRestricted( void EdgeBasedGraphFactory::InsertEdgeBasedNode( NodeIterator u, NodeIterator v, + EdgeIterator e1, bool belongs_to_tiny_cc ) { // merge edges together into one EdgeBasedNode - BOOST_ASSERT( u != std::numeric_limits::max() ); - BOOST_ASSERT( v != std::numeric_limits::max() ); + BOOST_ASSERT( u != SPECIAL_NODEID ); + BOOST_ASSERT( v != SPECIAL_NODEID ); + BOOST_ASSERT( e1 != SPECIAL_EDGEID ); // find forward edge id and - const EdgeID e1 = m_node_based_graph->FindEdge(u, v); + // const EdgeID e1 = m_node_based_graph->FindEdge(u, v); + BOOST_ASSERT( e1 != std::numeric_limits::max() ); const EdgeData & forward_data = m_node_based_graph->GetEdgeData(e1); + if( forward_data.edgeBasedNodeID == std::numeric_limits::max() ) { + for(EdgeIterator id = m_node_based_graph->BeginEdges(v); id < m_node_based_graph->EndEdges(v); ++id) { + SimpleLogger().Write(logDEBUG) << " id: " << id << ", edge (" << v << "," << m_node_based_graph->GetTarget(id) << ")"; + } + + SimpleLogger().Write() << "e1: " << e1 << "u: " << u << ", v: " << v; + SimpleLogger().Write() << std::setprecision(6) << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION << " <-> " << + 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() ); if( forward_data.ignore_in_grid ) { // SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," << // m_node_info_list[u].lon << " - " << // m_node_info_list[v].lat << "," << // m_node_info_list[v].lon; - return; } + BOOST_ASSERT( forward_data.forward ); + // find reverse edge id and const EdgeID e2 = m_node_based_graph->FindEdge(v, u); + if ( e2 == m_node_based_graph->EndEdges(v) ) { + SimpleLogger().Write(logDEBUG) << "Did not find edge (" << v << "," << u << ")"; + } 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); + // if( forward_data.forward == reverse_data.forward && forward_data.forward != forward_data.backward ) { + // SimpleLogger().Write(logDEBUG) << "flags on edge (" << u << "," << v << "), e1: " << e1 << ", e2: " << e2; + // SimpleLogger().Write(logDEBUG) << "fwd-fwd: " << (forward_data.forward ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "fwd-rev: " << (forward_data.backward ? "y": "n"); + // SimpleLogger().Write(logDEBUG) << "rev-fwd: " << (reverse_data.forward ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "rev-rev: " << (reverse_data.backward ? "y": "n"); + // SimpleLogger().Write(logDEBUG) << "outgoing edges to "; + // for(EdgeIterator id = m_node_based_graph->BeginEdges(v); id < m_node_based_graph->EndEdges(v); ++id) { + // SimpleLogger().Write(logDEBUG) << " id: " << id << ", edge (" << v << "," << m_node_based_graph->GetTarget(id) << ")"; + // } + // BOOST_ASSERT( reverse_data.edgeBasedNodeID != std::numeric_limits::max() ); + // } else { + // BOOST_ASSERT( reverse_data.edgeBasedNodeID == std::numeric_limits::max() ); + // } + if( m_geometry_compressor.HasEntryForID(e1) ) { BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e2) ); @@ -300,34 +350,96 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( const std::vector & reverse_geometry = m_geometry_compressor.GetBucketReference(e2); BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); BOOST_ASSERT( 0 != forward_geometry.size() ); - for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { - if( forward_geometry[i].first != reverse_geometry[reverse_geometry.size()-1-i].first ) { -#ifndef NDEBUG - //Dumps debug information when data is borked - SimpleLogger().Write() << "size1: " << forward_geometry.size() << ", size2: " << reverse_geometry.size(); - SimpleLogger().Write() << "index1: " << i << ", index2: " << reverse_geometry.size()-1-i; - SimpleLogger().Write() << forward_geometry[0].first << "!=" << reverse_geometry[reverse_geometry.size()-1-i].first; - BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, forward_geometry) { - SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; - } - BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { - SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; - } -#endif - } - BOOST_ASSERT( forward_geometry[i].first == reverse_geometry[reverse_geometry.size()-1-i].first ); - - //TODO reconstruct bidirectional edge with weights. - - +// for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { +// if( forward_geometry[i].first != reverse_geometry.back().first ) { +// #ifndef NDEBUG +// //Dumps debug information when data is borked +// SimpleLogger().Write() << "size1: " << forward_geometry.size() << ", size2: " << reverse_geometry.size(); +// SimpleLogger().Write() << "index1: " << i << ", index2: " << reverse_geometry.size()-1-i; +// SimpleLogger().Write() << forward_geometry[0].first << "!=" << reverse_geometry[reverse_geometry.size()-1-i].first; +// BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, forward_geometry) { +// SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; +// } +// BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { +// SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; +// } +// #endif +// } +// BOOST_ASSERT( forward_geometry[i].first == reverse_geometry[reverse_geometry.size()-1-i].first ); +// } + //TODO reconstruct bidirectional edge with weights. + int fwd_sum_of_weights = 0; + NodeID fwd_start_node = u; + // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; + SimpleLogger().Write(logDEBUG) << "fwd edge id: " << e1; + BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, forward_geometry) { + NodeID fwd_end_node = geometry_node.first; + EdgeWeight fwd_weight = geometry_node.second; + // SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; + fwd_sum_of_weights += geometry_node.second; + SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << fwd_end_node << "), w: " << fwd_weight; + fwd_start_node = fwd_end_node; } + SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << v << "), w: " << (forward_data.distance - fwd_sum_of_weights); + + // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; + // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; + // BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { + // SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; + // } + // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; + + SimpleLogger().Write(logDEBUG) << "fwd sum of edge weights: " << fwd_sum_of_weights; + SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << forward_data.distance; + SimpleLogger().Write(logDEBUG) << "weight diff: " << (forward_data.distance - fwd_sum_of_weights); + + + int rev_sum_of_weights = 0; + NodeID rev_start_node = v; + // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; + BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { + NodeID rev_end_node = geometry_node.first; + EdgeWeight rev_weight = geometry_node.second; + + // SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; + rev_sum_of_weights += geometry_node.second; + SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << rev_end_node << "), w: " << rev_weight; + rev_start_node = rev_end_node; + } + SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << u << "), w: " << (reverse_data.distance - rev_sum_of_weights); + + SimpleLogger().Write(logDEBUG) << "rev sum of edge weights: " << rev_sum_of_weights; + SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << reverse_data.distance; + SimpleLogger().Write(logDEBUG) << "weight diff: " << (reverse_data.distance - rev_sum_of_weights); + + + BOOST_ASSERT(false); + // SimpleLogger().Write(logDEBUG) << "start " << m_node_info_list[u].lat << "," << m_node_info_list[u].lon; // SimpleLogger().Write(logDEBUG) << "target " << m_node_info_list[v].lat << "," << m_node_info_list[v].lon; // BOOST_ASSERT( false ); - } //else { - //TODO: emplace back with C++11 + } else { + BOOST_ASSERT( !m_geometry_compressor.HasEntryForID(e2) ); + + if( forward_data.edgeBasedNodeID != std::numeric_limits::max() ) { + BOOST_ASSERT( forward_data.forward ); + } + if( reverse_data.edgeBasedNodeID != std::numeric_limits::max() ) { + BOOST_ASSERT( reverse_data.forward ); + } + if( forward_data.edgeBasedNodeID == std::numeric_limits::max() ) { + BOOST_ASSERT( !forward_data.forward ); + } + if( reverse_data.edgeBasedNodeID == std::numeric_limits::max() ) { + BOOST_ASSERT( !reverse_data.forward ); + } + + // BOOST_ASSERT( forward_data.forward == reverse_data.backward ); + // BOOST_ASSERT( reverse_data.forward == forward_data.backward ); + + //TODO: emplace_back with C++11 m_edge_based_node_list.push_back( EdgeBasedNode( forward_data.edgeBasedNodeID, @@ -344,7 +456,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( 0 ) ); - // } + } } @@ -372,6 +484,7 @@ void EdgeBasedGraphFactory::Run( SimpleLogger().Write(logDEBUG) << "Input graph has " << original_number_of_nodes << " nodes and " << original_number_of_edges << " edges"; Percent p(original_number_of_nodes); unsigned removed_node_count = 0; + for( NodeID v = 0; v < original_number_of_nodes; ++v ) { p.printStatus(v); @@ -402,6 +515,7 @@ void EdgeBasedGraphFactory::Run( BOOST_ASSERT( u != v ); const EdgeIterator forward_e1 = m_node_based_graph->FindEdge(u, v); + BOOST_ASSERT( m_node_based_graph->EndEdges(u) != forward_e1 ); BOOST_ASSERT( std::numeric_limits::max() != forward_e1 ); BOOST_ASSERT( v == m_node_based_graph->GetTarget(forward_e1)); const EdgeIterator reverse_e1 = m_node_based_graph->FindEdge(w, v); @@ -411,8 +525,9 @@ void EdgeBasedGraphFactory::Run( const EdgeData & fwd_edge_data1 = m_node_based_graph->GetEdgeData(forward_e1); const EdgeData & rev_edge_data1 = m_node_based_graph->GetEdgeData(reverse_e1); - if( m_node_based_graph->FindEdge(u, w) != m_node_based_graph->EndEdges(u) || - m_node_based_graph->FindEdge(w, u) != m_node_based_graph->EndEdges(w) + if( + ( m_node_based_graph->FindEdge(u, w) != m_node_based_graph->EndEdges(u) ) || + ( m_node_based_graph->FindEdge(w, u) != m_node_based_graph->EndEdges(w) ) ) { continue; } @@ -421,20 +536,42 @@ void EdgeBasedGraphFactory::Run( fwd_edge_data1.IsEqualTo(fwd_edge_data2) && rev_edge_data1.IsEqualTo(rev_edge_data2) ) { - // extend e1's to targets of e2's - m_node_based_graph->SetTarget(forward_e1, w); - m_node_based_graph->SetTarget(reverse_e1, u); + //Get distances before graph is modified + const bool fwd_e1_is_compressed = m_geometry_compressor.HasEntryForID(forward_e1); + int forward_weight1 = 0; + if( fwd_e1_is_compressed ) { + forward_weight1 = m_geometry_compressor.GetBucketReference(forward_e1).back().second; + } else { + forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; + } + if( 0 == forward_e1 ) { + SimpleLogger().Write(logDEBUG) << (fwd_e1_is_compressed ? "fetched" : "used") << " fwd weight: " << forward_weight1; + } - const int forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; + BOOST_ASSERT( 0 != forward_weight1 ); // const int forward_weight2 = fwd_edge_data2.distance; - const int reverse_weight1 = m_node_based_graph->GetEdgeData(reverse_e1).distance; - // const int reverse_weight2 = rev_edge_data2.distance; + const bool rev_e1_is_compressed = m_geometry_compressor.HasEntryForID(reverse_e1); + int reverse_weight1 = 0; + if( rev_e1_is_compressed ) { + reverse_weight1 = m_geometry_compressor.GetBucketReference(reverse_e1).back().second; + } else { + reverse_weight1 = m_node_based_graph->GetEdgeData(reverse_e1).distance; + } + BOOST_ASSERT( 0 != reverse_weight1 ); + if( 0 == reverse_e1 ) { + SimpleLogger().Write(logDEBUG) << (rev_e1_is_compressed ? "fetched" : "used") << " fwd weight: " << reverse_weight1; + } + // add weight of e2's to e1 m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance; m_node_based_graph->GetEdgeData(reverse_e1).distance += rev_edge_data2.distance; + // extend e1's to targets of e2's + m_node_based_graph->SetTarget(forward_e1, w); + m_node_based_graph->SetTarget(reverse_e1, u); + // remove e2's (if bidir, otherwise only one) m_node_based_graph->DeleteEdge(v, forward_e2); m_node_based_graph->DeleteEdge(v, reverse_e2); @@ -446,6 +583,8 @@ void EdgeBasedGraphFactory::Run( FixupStartingTurnRestriction( w, v, u ); FixupArrivingTurnRestriction( w, v, u ); + // const int reverse_weight2 = rev_edge_data2.distance; + // store compressed geometry in container m_geometry_compressor.CompressEdge( forward_e1, @@ -477,48 +616,28 @@ void EdgeBasedGraphFactory::Run( } } SimpleLogger().Write() << "new nodes: " << new_node_count << ", edges " << new_edge_count; + SimpleLogger().Write(logDEBUG) << "Graph reports: " << m_node_based_graph->GetNumberOfEdges() << " edges"; SimpleLogger().Write() << "Node compression ratio: " << new_node_count/(double)original_number_of_nodes; SimpleLogger().Write() << "Edge compression ratio: " << new_edge_count/(double)original_number_of_edges; - //Extract routing graph + // renumber edge based node IDs unsigned numbered_edges_count = 0; - for(NodeID source = 0; source < m_node_based_graph->GetNumberOfNodes(); ++source) { - for( - EdgeID current_edge_id = m_node_based_graph->BeginEdges(source); - current_edge_id < m_node_based_graph->EndEdges(source); - ++current_edge_id - ) { - const NodeID target = m_node_based_graph->GetTarget(current_edge_id); - EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge_id); - if( 0 == numbered_edges_count ){ - SimpleLogger().Write(logDEBUG) << "uninitialized edge based node id: " << edge_data.edgeBasedNodeID; - } + for(NodeID current_node = 0; current_node < m_node_based_graph->GetNumberOfNodes(); ++current_node) { + for(EdgeIterator current_edge = m_node_based_graph->BeginEdges(current_node); current_edge < m_node_based_graph->EndEdges(current_node); ++current_edge) { + EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge); if( !edge_data.forward ) { // SimpleLogger().Write(logDEBUG) << "skipped edge (" << source << "," << target << ")=[" << current_edge_id << "]"; continue; } - if( edge_data.edgeBasedNodeID != std::numeric_limits::max() ) {//source > target ) { - // SimpleLogger().Write(logDEBUG) << "skipping edge based node id: " << edge_data.edgeBasedNodeID; - continue; - } BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); edge_data.edgeBasedNodeID = numbered_edges_count; ++numbered_edges_count; - const EdgeID reverse_edge_id = m_node_based_graph->FindEdge(target, source); - BOOST_ASSERT( reverse_edge_id != m_node_based_graph->EndEdges(target)); - - EdgeData & reverse_edge_data = m_node_based_graph->GetEdgeData(reverse_edge_id); - if( !reverse_edge_data.forward ) { - continue; - } - - BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); - reverse_edge_data.edgeBasedNodeID = numbered_edges_count; - ++numbered_edges_count; + BOOST_ASSERT( std::numeric_limits::max() != edge_data.edgeBasedNodeID); } } + SimpleLogger().Write(logDEBUG) << "numbered " << numbered_edges_count << " edge-expanded nodes"; SimpleLogger().Write() << "Identifying components of the road network"; @@ -538,8 +657,8 @@ void EdgeBasedGraphFactory::Run( //Run a BFS on the undirected graph and identify small components std::vector component_index_list; - std::vector component_index_size; - BFSCompentExplorer( component_index_list, component_index_size); + std::vector component_index_size; + BFSCompentExplorer( component_index_list, component_index_size ); SimpleLogger().Write() << "identified: " << component_index_size.size() << " many components"; @@ -563,6 +682,10 @@ void EdgeBasedGraphFactory::Run( e1 < last_edge; ++e1 ) { + const EdgeData & edge_data = m_node_based_graph->GetEdgeData(e1); + if( edge_data.edgeBasedNodeID == std::numeric_limits::max() ) { + continue; + } BOOST_ASSERT( e1 != std::numeric_limits::max() ); NodeIterator v = m_node_based_graph->GetTarget(e1); BOOST_ASSERT( std::numeric_limits::max() != v ); @@ -571,9 +694,7 @@ void EdgeBasedGraphFactory::Run( continue; } BOOST_ASSERT( u < v ); - BOOST_ASSERT( - m_node_based_graph->GetEdgeData(e1).type != SHRT_MAX - ); + BOOST_ASSERT( edge_data.type != SHRT_MAX ); //Note: edges that end on barrier nodes or on a turn restriction //may actually be in two distinct components. We choose the smallest @@ -582,16 +703,45 @@ void EdgeBasedGraphFactory::Run( component_index_size[component_index_list[v]] ); - InsertEdgeBasedNode( u, v, size_of_component < 1000 ); + const bool component_is_tiny = ( size_of_component < 1000 ); + + InsertEdgeBasedNode( u, v, e1, component_is_tiny ); } } - //TODO: check if correct, suspect two off by ones here + // for( + // NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes(); + // u < end; + // ++u + // ) { + // BOOST_ASSERT( u != std::numeric_limits::max() ); + // BOOST_ASSERT( u < m_node_based_graph->GetNumberOfNodes() ); + // p.printIncrement(); + // for( + // EdgeIterator e1 = m_node_based_graph->BeginEdges(u), + // last_edge = m_node_based_graph->EndEdges(u); + // e1 < last_edge; + // ++e1 + // ) { + // BOOST_ASSERT( e1 != std::numeric_limits::max() ); + // NodeIterator v = m_node_based_graph->GetTarget(e1); + + // EdgeIterator e2 = m_node_based_graph->FindEdge(u, v); + // BOOST_ASSERT( e2 != m_node_based_graph->EndEdges(v) ); + // BOOST_ASSERT( e1 == e2 ); + + // const EdgeData & data = m_node_based_graph->GetEdgeData(e1); + // if( data.forward ) { + // BOOST_ASSERT( data.edgeBasedNodeID != std::numeric_limits::max() ); + // } + + // } + // } + m_number_of_edge_based_nodes = numbered_edges_count; - SimpleLogger().Write() - << "Generated " << m_edge_based_node_list.size() << " nodes in " << - "edge-expanded graph"; + SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << + " nodes in edge-expanded graph"; SimpleLogger().Write() << "generating edge-expanded edges"; std::vector().swap(component_index_size); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index f8269c2f8..875af6edb 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -181,6 +181,7 @@ private: void InsertEdgeBasedNode( NodeBasedDynamicGraph::NodeIterator u, NodeBasedDynamicGraph::NodeIterator v, + NodeBasedDynamicGraph::EdgeIterator e1, bool belongsToTinyComponent ); diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 83157a27d..43c0477ff 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -146,10 +146,10 @@ void GeometryCompressor::CompressEdge( // const EdgeWeight weight2 ) { - BOOST_ASSERT( UINT_MAX != surviving_edge_id ); - BOOST_ASSERT( UINT_MAX != removed_edge_id ); - BOOST_ASSERT( UINT_MAX != via_node_id ); - + BOOST_ASSERT( SPECIAL_EDGEID != surviving_edge_id ); + BOOST_ASSERT( SPECIAL_NODEID != removed_edge_id ); + BOOST_ASSERT( SPECIAL_NODEID != via_node_id ); + BOOST_ASSERT( std::numeric_limits::max() != weight1 ); // append list of removed edge_id plus via node to surviving edge id: // & surviving_geometry_list = m_compressed_geometries[surving_list_id]; - if( !surviving_geometry_list.empty() ) { - BOOST_ASSERT( via_node_id != surviving_geometry_list.back().first ); + BOOST_ASSERT( + surviving_geometry_list.empty() || + ( via_node_id != surviving_geometry_list.back().first ) + ); + + if(surviving_edge_id == 0) { + SimpleLogger().Write(logDEBUG) << "adding via " << via_node_id << ", w: " << weight1; } + surviving_geometry_list.push_back( std::make_pair(via_node_id, weight1) ); BOOST_ASSERT( 0 < surviving_geometry_list.size() ); BOOST_ASSERT( !surviving_geometry_list.empty() ); @@ -195,6 +201,14 @@ void GeometryCompressor::CompressEdge( BOOST_ASSERT( list_to_remove_index < m_compressed_geometries.size() ); std::vector & remove_geometry_list = m_compressed_geometries[list_to_remove_index]; + if(surviving_edge_id == 0) { + SimpleLogger().Write(logDEBUG) << "appending to list: "; + BOOST_FOREACH(const CompressedNode & node, remove_geometry_list) { + SimpleLogger().Write(logDEBUG) << "adding via " << node.first << ", w: " << node.second; + } + } + + // found an existing list, append it to the list of surviving_edge_id surviving_geometry_list.insert( surviving_geometry_list.end(), diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 880e1e707..1006d2bb3 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -61,7 +61,8 @@ public: bool ra, bool ig, bool ar, - bool cf + bool cf, + bool is_split ) : _source(s), _target(t), _name(n), @@ -72,7 +73,8 @@ public: _roundabout(ra), _ignoreInGrid(ig), _accessRestricted(ar), - _contraFlow(cf) + _contraFlow(cf), + is_split(is_split) { if(ty < 0) { throw OSRMException("negative edge type"); @@ -93,6 +95,7 @@ public: bool ignoreInGrid() const { return _ignoreInGrid; } bool isAccessRestricted() const { return _accessRestricted; } bool isContraFlow() const { return _contraFlow; } + bool IsSplit() const { return is_split; } //TODO: names need to be fixed. NodeID _source; @@ -106,6 +109,7 @@ public: bool _ignoreInGrid:1; bool _accessRestricted:1; bool _contraFlow:1; + bool is_split:1; private: NodeBasedEdge() { } diff --git a/DataStructures/ImportNode.h b/DataStructures/ImportNode.h index f249a6433..f409a3be6 100644 --- a/DataStructures/ImportNode.h +++ b/DataStructures/ImportNode.h @@ -44,11 +44,17 @@ struct ExternalMemoryNode : NodeInfo { bollard(bollard), trafficLight(traffic_light) { } - ExternalMemoryNode() : bollard(false), trafficLight(false) {} + + ExternalMemoryNode() + : + bollard(false), + trafficLight(false) + { } static ExternalMemoryNode min_value() { return ExternalMemoryNode(0,0,0, false, false); } + static ExternalMemoryNode max_value() { return ExternalMemoryNode( std::numeric_limits::max(), @@ -58,9 +64,11 @@ struct ExternalMemoryNode : NodeInfo { false ); } + NodeID key() const { return id; } + bool bollard; bool trafficLight; }; diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 893586d62..03ffb92f6 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -33,9 +33,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct PhantomNode { PhantomNode() : - forward_node_id(UINT_MAX), - reverse_node_id(UINT_MAX), - name_id(UINT_MAX), + 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), ratio(0.) @@ -50,15 +50,15 @@ struct PhantomNode { FixedPointCoordinate location; void Reset() { - forward_node_id = UINT_MAX; - name_id = UINT_MAX; + forward_node_id = std::numeric_limits::max(); + name_id = std::numeric_limits::max(); forward_weight = INT_MAX; reverse_weight = INT_MAX; ratio = 0.; location.Reset(); } bool isBidirected() const { - return forward_weight != INT_MAX && reverse_weight != INT_MAX; + return forward_node_id != UINT_MAX && reverse_node_id != UINT_MAX; } bool isValid(const unsigned numberOfNodes) const { return @@ -67,7 +67,7 @@ struct PhantomNode { ( (forward_weight != INT_MAX) || (reverse_weight != INT_MAX) ) && (ratio >= 0.) && (ratio <= 1.) && - (name_id != UINT_MAX); + (name_id != std::numeric_limits::max()); } bool operator==(const PhantomNode & other) const { @@ -88,7 +88,7 @@ struct PhantomNodes { } bool AtLeastOnePhantomNodeIsUINTMAX() const { - return !(startPhantom.forward_node_id == UINT_MAX || targetPhantom.forward_node_id == UINT_MAX); + return !(startPhantom.forward_node_id == std::numeric_limits::max() || targetPhantom.forward_node_id == std::numeric_limits::max()); } bool PhantomNodesHaveEqualLocation() const { diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 62aa2a056..7821ce0dc 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -722,6 +722,11 @@ public: } result_phantom_node.ratio = ratio; + SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location; + SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; + SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight << ", ratio: " << result_phantom_node.ratio; + + return found_a_nearest_edge; } diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index dc1a7ff60..c8f801705 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -373,23 +373,27 @@ void ExtractionContainers::PrepareData( sizeof(short) ); file_out_stream.write( - (char*)&edge_iterator->nameID, + (char *) &edge_iterator->nameID, sizeof(unsigned) ); file_out_stream.write( - (char*)&edge_iterator->isRoundabout, + (char *) &edge_iterator->isRoundabout, sizeof(bool) ); file_out_stream.write( - (char*)&edge_iterator->ignoreInGrid, + (char *) &edge_iterator->ignoreInGrid, sizeof(bool) ); file_out_stream.write( - (char*)&edge_iterator->isAccessRestricted, + (char *) &edge_iterator->isAccessRestricted, sizeof(bool) ); file_out_stream.write( - (char*)&edge_iterator->isContraFlow, + (char *) &edge_iterator->isContraFlow, + sizeof(bool) + ); + file_out_stream.write( + (char *) &edge_iterator->is_split, sizeof(bool) ); ++number_of_used_edges; diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index e97275749..0dc5ac8aa 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -36,8 +36,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include - #include #include #include @@ -113,16 +111,19 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) { for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) { externalMemory->all_edges_list.push_back( - InternalExtractorEdge(parsed_way.path[n], - parsed_way.path[n+1], - parsed_way.type, - (split_bidirectional_edge ? ExtractionWay::oneway : parsed_way.direction), - parsed_way.speed, - parsed_way.nameID, - parsed_way.roundabout, - parsed_way.ignoreInGrid, - (0 < parsed_way.duration), - parsed_way.isAccessRestricted + InternalExtractorEdge( + parsed_way.path[n], + parsed_way.path[n+1], + parsed_way.type, + (split_bidirectional_edge ? ExtractionWay::oneway : parsed_way.direction), + parsed_way.speed, + parsed_way.nameID, + parsed_way.roundabout, + parsed_way.ignoreInGrid, + (0 < parsed_way.duration), + parsed_way.isAccessRestricted, + false, + split_bidirectional_edge ) ); externalMemory->used_node_id_list.push_back(parsed_way.path[n]); @@ -136,17 +137,19 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) { std::reverse( parsed_way.path.begin(), parsed_way.path.end() ); for(std::vector< NodeID >::size_type n = 0; n < parsed_way.path.size()-1; ++n) { externalMemory->all_edges_list.push_back( - InternalExtractorEdge(parsed_way.path[n], - parsed_way.path[n+1], - parsed_way.type, - ExtractionWay::oneway, - parsed_way.backward_speed, - parsed_way.nameID, - parsed_way.roundabout, - parsed_way.ignoreInGrid, - (0 < parsed_way.duration), - parsed_way.isAccessRestricted, - (ExtractionWay::oneway == parsed_way.direction) + InternalExtractorEdge( + parsed_way.path[n], + parsed_way.path[n+1], + parsed_way.type, + ExtractionWay::oneway, + parsed_way.backward_speed, + parsed_way.nameID, + parsed_way.roundabout, + parsed_way.ignoreInGrid, + (0 < parsed_way.duration), + parsed_way.isAccessRestricted, + (ExtractionWay::oneway == parsed_way.direction), + split_bidirectional_edge ) ); } diff --git a/Extractor/InternalExtractorEdge.h b/Extractor/InternalExtractorEdge.h index 3dca1fa1d..e504d4fd1 100644 --- a/Extractor/InternalExtractorEdge.h +++ b/Extractor/InternalExtractorEdge.h @@ -28,9 +28,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INTERNAL_EXTRACTOR_EDGE_H #define INTERNAL_EXTRACTOR_EDGE_H -#include #include "../typedefs.h" +#include #include @@ -47,70 +47,10 @@ struct InternalExtractorEdge { ignoreInGrid(false), isDurationSet(false), isAccessRestricted(false), - isContraFlow(false) + isContraFlow(false), + is_split(false) { } - explicit InternalExtractorEdge(NodeID start, NodeID target) - : - start(start), - target(target), - type(0), - direction(0), - speed(0), - nameID(0), - isRoundabout(false), - ignoreInGrid(false), - isDurationSet(false), - isAccessRestricted(false), - isContraFlow(false) - { } - - explicit InternalExtractorEdge( - NodeID start, - NodeID target, - short type, - short d, - double speed - ) : - start(start), - target(target), - type(type), - direction(d), - speed(speed), - nameID(0), - isRoundabout(false), - ignoreInGrid(false), - isDurationSet(false), - isAccessRestricted(false), - isContraFlow(false) - { } - - explicit InternalExtractorEdge( - NodeID start, - NodeID target, - short type, - short direction, - double speed, - unsigned nameID, - bool isRoundabout, - bool ignoreInGrid, - bool isDurationSet, - bool isAccressRestricted - ) : - start(start), - target(target), - type(type), - direction(direction), - speed(speed), - nameID(nameID), - isRoundabout(isRoundabout), - ignoreInGrid(ignoreInGrid), - isDurationSet(isDurationSet), - isAccessRestricted(isAccressRestricted), - isContraFlow(false) - { - BOOST_ASSERT(0 <= type); - } explicit InternalExtractorEdge( NodeID start, @@ -123,7 +63,8 @@ struct InternalExtractorEdge { bool ignoreInGrid, bool isDurationSet, bool isAccressRestricted, - bool isContraFlow + bool isContraFlow, + bool is_split ) : start(start), target(target), @@ -135,19 +76,43 @@ struct InternalExtractorEdge { ignoreInGrid(ignoreInGrid), isDurationSet(isDurationSet), isAccessRestricted(isAccressRestricted), - isContraFlow(isContraFlow) + isContraFlow(isContraFlow), + is_split(is_split) { BOOST_ASSERT(0 <= type); } // necessary static util functions for stxxl's sorting static InternalExtractorEdge min_value() { - return InternalExtractorEdge(0,0); + return InternalExtractorEdge( + 0, + 0, + 0, + 0, + 0, + 0, + false, + false, + false, + false, + false, + false + ); } static InternalExtractorEdge max_value() { return InternalExtractorEdge( std::numeric_limits::max(), - std::numeric_limits::max() + std::numeric_limits::max(), + 0, + 0, + 0, + 0, + false, + false, + false, + false, + false, + false ); } @@ -162,6 +127,7 @@ struct InternalExtractorEdge { bool isDurationSet; bool isAccessRestricted; bool isContraFlow; + bool is_split; FixedPointCoordinate startCoord; FixedPointCoordinate targetCoord; diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index c51ddd813..998e2f198 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -66,7 +66,7 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) { luabind::module(myLuaState) [ luabind::class_ >("keyVals") .def("Add", &HashTable::Add) - .def("Get", &HashTable::Get) + .def("Find", &HashTable::Find) .def("Holds", &HashTable::Holds) ]; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 3785da6b2..37174b3b2 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -136,7 +136,7 @@ NodeID readBinaryOSRMGraphFromStream( short type; NodeID nameID; int length; - bool isRoundabout, ignoreInGrid, isAccessRestricted, isContraFlow; + bool isRoundabout, ignoreInGrid, isAccessRestricted, isContraFlow, is_split; for (EdgeID i=0; i 0, "loaded null length edge" ); BOOST_ASSERT_MSG(weight > 0, "loaded null weight"); @@ -190,7 +191,7 @@ NodeID readBinaryOSRMGraphFromStream( std::swap(forward, backward); } - EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout, ignoreInGrid, isAccessRestricted, isContraFlow ); + EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout, ignoreInGrid, isAccessRestricted, isContraFlow, is_split ); edge_list.push_back(inputEdge); } std::sort(edge_list.begin(), edge_list.end()); From f16cb3c52d2aa2c7ec8da794848a60f110a2343e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 20 Feb 2014 17:49:18 +0100 Subject: [PATCH 11/89] compressed geometries get serialized in R-tree --- Contractor/EdgeBasedGraphFactory.cpp | 203 +++++++++++++++++---------- Contractor/GeometryCompressor.cpp | 106 ++++++-------- Contractor/GeometryCompressor.h | 19 +-- 3 files changed, 181 insertions(+), 147 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 81f27264c..f8487aab5 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include EdgeBasedGraphFactory::EdgeBasedGraphFactory( int number_of_nodes, @@ -301,12 +302,11 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( for(EdgeIterator id = m_node_based_graph->BeginEdges(v); id < m_node_based_graph->EndEdges(v); ++id) { SimpleLogger().Write(logDEBUG) << " id: " << id << ", edge (" << v << "," << m_node_based_graph->GetTarget(id) << ")"; } - - SimpleLogger().Write() << "e1: " << e1 << "u: " << u << ", v: " << v; SimpleLogger().Write() << std::setprecision(6) << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION << " <-> " << 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; if( forward_data.ignore_in_grid ) { // SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," << @@ -320,9 +320,11 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( // find reverse edge id and const EdgeID e2 = m_node_based_graph->FindEdge(v, u); +#ifndef NDEBUG if ( e2 == m_node_based_graph->EndEdges(v) ) { SimpleLogger().Write(logDEBUG) << "Did not find edge (" << v << "," << u << ")"; } +#endif NDEBUG 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); @@ -350,76 +352,136 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( const std::vector & reverse_geometry = m_geometry_compressor.GetBucketReference(e2); BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); BOOST_ASSERT( 0 != forward_geometry.size() ); -// for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { -// if( forward_geometry[i].first != reverse_geometry.back().first ) { -// #ifndef NDEBUG -// //Dumps debug information when data is borked -// SimpleLogger().Write() << "size1: " << forward_geometry.size() << ", size2: " << reverse_geometry.size(); -// SimpleLogger().Write() << "index1: " << i << ", index2: " << reverse_geometry.size()-1-i; -// SimpleLogger().Write() << forward_geometry[0].first << "!=" << reverse_geometry[reverse_geometry.size()-1-i].first; -// BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, forward_geometry) { -// SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; -// } -// BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { -// SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; -// } -// #endif -// } -// BOOST_ASSERT( forward_geometry[i].first == reverse_geometry[reverse_geometry.size()-1-i].first ); -// } - //TODO reconstruct bidirectional edge with weights. int fwd_sum_of_weights = 0; NodeID fwd_start_node = u; // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - SimpleLogger().Write(logDEBUG) << "fwd edge id: " << e1; - BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, forward_geometry) { - NodeID fwd_end_node = geometry_node.first; - EdgeWeight fwd_weight = geometry_node.second; + // if( 1 == e1 ) { + // SimpleLogger().Write(logDEBUG) << "fwd edge id: " << e1; + // } + BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, forward_geometry) { + const NodeID fwd_end_node = geometry_node.first; + const EdgeWeight fwd_weight = geometry_node.second; // SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; - fwd_sum_of_weights += geometry_node.second; - SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << fwd_end_node << "), w: " << fwd_weight; + fwd_sum_of_weights += fwd_weight; + // if( 1 == e1 ) { + // SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << fwd_end_node << "), w: " << fwd_weight; + // } fwd_start_node = fwd_end_node; } - SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << v << "), w: " << (forward_data.distance - fwd_sum_of_weights); + // if( 1 == e1 ) { + // SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << v << "), w: " << (forward_data.distance - fwd_sum_of_weights); + // } + // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; + // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; + // BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { + // SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; + // } + // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; - // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; - // BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { - // SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; - // } - // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - - SimpleLogger().Write(logDEBUG) << "fwd sum of edge weights: " << fwd_sum_of_weights; - SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << forward_data.distance; - SimpleLogger().Write(logDEBUG) << "weight diff: " << (forward_data.distance - fwd_sum_of_weights); + // if( 1 == e1 ) { + // SimpleLogger().Write(logDEBUG) << "fwd sum of edge weights: " << fwd_sum_of_weights; + // SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << forward_data.distance; + // SimpleLogger().Write(logDEBUG) << "weight diff: " << (forward_data.distance - fwd_sum_of_weights); + // } + BOOST_ASSERT( forward_data.distance == fwd_sum_of_weights ); int rev_sum_of_weights = 0; NodeID rev_start_node = v; // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { - NodeID rev_end_node = geometry_node.first; - EdgeWeight rev_weight = geometry_node.second; + BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, reverse_geometry) { + const NodeID rev_end_node = geometry_node.first; + const EdgeWeight rev_weight = geometry_node.second; - // SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; - rev_sum_of_weights += geometry_node.second; - SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << rev_end_node << "), w: " << rev_weight; + // SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; + rev_sum_of_weights += rev_weight; + // if( 1 == e1 ) { + // SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << rev_end_node << "), w: " << rev_weight; + // } rev_start_node = rev_end_node; } - SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << u << "), w: " << (reverse_data.distance - rev_sum_of_weights); + // if( 1 == e1 ) { + // SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << u << "), w: " << (reverse_data.distance - rev_sum_of_weights); - SimpleLogger().Write(logDEBUG) << "rev sum of edge weights: " << rev_sum_of_weights; - SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << reverse_data.distance; - SimpleLogger().Write(logDEBUG) << "weight diff: " << (reverse_data.distance - rev_sum_of_weights); - - - BOOST_ASSERT(false); + // SimpleLogger().Write(logDEBUG) << "rev sum of edge weights: " << rev_sum_of_weights; + // SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << reverse_data.distance; + // SimpleLogger().Write(logDEBUG) << "weight diff: " << (reverse_data.distance - rev_sum_of_weights); + BOOST_ASSERT( reverse_data.distance == rev_sum_of_weights ); + // // BOOST_ASSERT(false); + // } // SimpleLogger().Write(logDEBUG) << "start " << m_node_info_list[u].lat << "," << m_node_info_list[u].lon; // SimpleLogger().Write(logDEBUG) << "target " << m_node_info_list[v].lat << "," << m_node_info_list[v].lon; // BOOST_ASSERT( false ); + + //TODO reconstruct bidirectional edge with individual weights and put each into the NN index + + std::vector forward_dist_prefix_sum( forward_geometry.size() ); + std::vector reverse_dist_prefix_sum( reverse_geometry.size() ); + + //quick'n'dirty prefix sum as std::partial_sum needs addtional casts + // SimpleLogger().Write(logDEBUG) << "Prefix sums of edge " << e1 << ", w: " << reverse_data.distance; + int temp_sum = 0; + for( unsigned i = 0; i < forward_geometry.size(); ++i ) { + temp_sum += forward_geometry[i].second; + BOOST_ASSERT( forward_data.distance >= temp_sum ); + forward_dist_prefix_sum[i] = forward_data.distance - temp_sum; + // SimpleLogger().Write(logDEBUG) << "[" << i << "]" << temp_sum << ", n: " << forward_geometry[i].first << ", loc: " << m_node_info_list[forward_geometry[i].first].lat/COORDINATE_PRECISION << "," << m_node_info_list[forward_geometry[i].first].lon/COORDINATE_PRECISION; + } + BOOST_ASSERT( forward_data.distance == temp_sum ); + temp_sum = 0; + for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { + temp_sum += reverse_geometry[i].second; + BOOST_ASSERT( reverse_data.distance >= temp_sum ); + reverse_dist_prefix_sum[i] = reverse_data.distance - temp_sum; + // SimpleLogger().Write(logDEBUG) << "[" << i << "]" << temp_sum << ", n: " << reverse_geometry[i].first << ", loc: " << m_node_info_list[reverse_geometry[i].first].lat/COORDINATE_PRECISION << "," << m_node_info_list[reverse_geometry[i].first].lon/COORDINATE_PRECISION; + } + BOOST_ASSERT( reverse_data.distance == temp_sum ); + + BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); + + const unsigned geometry_size = forward_geometry.size(); + NodeID first_node_of_edge = u; + // traverse arrays from start and end respectively + for( unsigned i = 0; i < geometry_size; ++i ) { + BOOST_ASSERT( first_node_of_edge == reverse_geometry[geometry_size-1-i].first ); + const NodeID last_coordinate_id = forward_geometry[i].first; + + // SimpleLogger().Write() << "adding edge (" << first_node_of_edge << "," << forward_geometry[i].first << ") "; + // SimpleLogger().Write() << "fwd w: " << forward_geometry[i].second << ", fwd o: " << forward_dist_prefix_sum[i]; + // SimpleLogger().Write() << "rev w: " << reverse_geometry[geometry_size-1-i].second << ", rev o: " << reverse_dist_prefix_sum[geometry_size-1-i]; + + //TODO: build edges + m_edge_based_node_list.push_back( + EdgeBasedNode( + forward_data.edgeBasedNodeID, + reverse_data.edgeBasedNodeID, + m_node_info_list[first_node_of_edge].lat, + m_node_info_list[first_node_of_edge].lon, + m_node_info_list[forward_geometry[i].first].lat, + m_node_info_list[forward_geometry[i].first].lon, + belongs_to_tiny_cc,//TODO + forward_data.nameID, + forward_geometry[i].second, + reverse_geometry[geometry_size-1-i].second, + forward_dist_prefix_sum[i], + reverse_dist_prefix_sum[geometry_size-1-i] + ) + ); + first_node_of_edge = last_coordinate_id; + } + //TODO: Manually reconstruct last edge. + + if( first_node_of_edge != v ) { + SimpleLogger().Write(logDEBUG) << "first_node_of_edge:" << first_node_of_edge << ", u: " << u << ", v: " << v; + } + + // BOOST_ASSERT( false ); + + BOOST_ASSERT( first_node_of_edge == v ); + } else { BOOST_ASSERT( !m_geometry_compressor.HasEntryForID(e2) ); @@ -537,32 +599,17 @@ void EdgeBasedGraphFactory::Run( rev_edge_data1.IsEqualTo(rev_edge_data2) ) { //Get distances before graph is modified - const bool fwd_e1_is_compressed = m_geometry_compressor.HasEntryForID(forward_e1); - int forward_weight1 = 0; - if( fwd_e1_is_compressed ) { - forward_weight1 = m_geometry_compressor.GetBucketReference(forward_e1).back().second; - } else { - forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; - } - if( 0 == forward_e1 ) { - SimpleLogger().Write(logDEBUG) << (fwd_e1_is_compressed ? "fetched" : "used") << " fwd weight: " << forward_weight1; - } + const int forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; + const int forward_weight2 = m_node_based_graph->GetEdgeData(forward_e2).distance; BOOST_ASSERT( 0 != forward_weight1 ); - // const int forward_weight2 = fwd_edge_data2.distance; + BOOST_ASSERT( 0 != forward_weight2 ); + + const int reverse_weight1 = m_node_based_graph->GetEdgeData(reverse_e1).distance; + const int reverse_weight2 = m_node_based_graph->GetEdgeData(reverse_e2).distance; - const bool rev_e1_is_compressed = m_geometry_compressor.HasEntryForID(reverse_e1); - int reverse_weight1 = 0; - if( rev_e1_is_compressed ) { - reverse_weight1 = m_geometry_compressor.GetBucketReference(reverse_e1).back().second; - } else { - reverse_weight1 = m_node_based_graph->GetEdgeData(reverse_e1).distance; - } BOOST_ASSERT( 0 != reverse_weight1 ); - if( 0 == reverse_e1 ) { - SimpleLogger().Write(logDEBUG) << (rev_e1_is_compressed ? "fetched" : "used") << " fwd weight: " << reverse_weight1; - } - + BOOST_ASSERT( 0 != forward_weight2 ); // add weight of e2's to e1 m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance; @@ -590,15 +637,17 @@ void EdgeBasedGraphFactory::Run( forward_e1, forward_e2, v, - forward_weight1//, - // forward_weight2 + w, + forward_weight1, + forward_weight2 ); m_geometry_compressor.CompressEdge( reverse_e1, reverse_e2, v, - reverse_weight1//, - // reverse_weight2 + u, + reverse_weight1, + reverse_weight2 ); ++removed_node_count; @@ -858,7 +907,7 @@ void EdgeBasedGraphFactory::Run( const bool edge_is_compressed = m_geometry_compressor.HasEntryForID(e1); if(edge_is_compressed) { ++compressed; - m_geometry_compressor.AddLastViaNodeIDToCompressedEdge(e1, v, /*TODO*/ 1); + // m_geometry_compressor.AddLastViaNodeIDToCompressedEdge(e1, v, /*TODO*/ 1); if ( 0 == m_geometry_compressor.GetPositionForID(e1) ) { SimpleLogger().Write(logDEBUG) << "e1: " << e1 << " is zero with via node: " << v; } diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 43c0477ff..e5974b602 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -61,23 +61,6 @@ unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const { return map_iterator->second; } -void GeometryCompressor::AddLastViaNodeIDToCompressedEdge( - const EdgeID edge_id, - const NodeID node_id, - const EdgeWeight weight -) { - unsigned index = GetPositionForID(edge_id); - BOOST_ASSERT( index < m_compressed_geometries.size() ); - if( !m_compressed_geometries[index].empty() ) { - if( m_compressed_geometries[index].back().first == node_id ) { - return; - } - } - BOOST_ASSERT( node_id != m_compressed_geometries[index].back().first ); - m_compressed_geometries[index].push_back( std::make_pair(node_id, weight) ); - BOOST_ASSERT( node_id == m_compressed_geometries[index].back().first ); -} - void GeometryCompressor::SerializeInternalVector( const std::string & path ) const { @@ -139,27 +122,31 @@ void GeometryCompressor::SerializeInternalVector( } void GeometryCompressor::CompressEdge( - const EdgeID surviving_edge_id, - const EdgeID removed_edge_id, + const EdgeID edge_id_1, + const EdgeID edge_id_2, const NodeID via_node_id, - const EdgeWeight weight1//, - // const EdgeWeight weight2 + const NodeID target_node_id, + const EdgeWeight weight1, + const EdgeWeight weight2 ) { - BOOST_ASSERT( SPECIAL_EDGEID != surviving_edge_id ); - BOOST_ASSERT( SPECIAL_NODEID != removed_edge_id ); - BOOST_ASSERT( SPECIAL_NODEID != via_node_id ); + BOOST_ASSERT( SPECIAL_EDGEID != edge_id_1 ); + BOOST_ASSERT( SPECIAL_EDGEID != edge_id_2 ); + BOOST_ASSERT( SPECIAL_NODEID != via_node_id ); + BOOST_ASSERT( SPECIAL_NODEID != target_node_id ); BOOST_ASSERT( std::numeric_limits::max() != weight1 ); + BOOST_ASSERT( std::numeric_limits::max() != weight2 ); + // append list of removed edge_id plus via node to surviving edge id: // & surviving_geometry_list = m_compressed_geometries[surving_list_id]; - BOOST_ASSERT( - surviving_geometry_list.empty() || - ( via_node_id != surviving_geometry_list.back().first ) - ); + std::vector & edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1]; - if(surviving_edge_id == 0) { + if( 0 == edge_id_1 ) { SimpleLogger().Write(logDEBUG) << "adding via " << via_node_id << ", w: " << weight1; } - surviving_geometry_list.push_back( std::make_pair(via_node_id, weight1) ); - BOOST_ASSERT( 0 < surviving_geometry_list.size() ); - BOOST_ASSERT( !surviving_geometry_list.empty() ); + if( edge_bucket_list1.empty() ) { + edge_bucket_list1.push_back( std::make_pair(via_node_id, weight1) ); + } - // Find any existing list for removed_edge_id - typename boost::unordered_map::const_iterator remove_list_iterator; - remove_list_iterator = m_edge_id_to_list_index_map.find(removed_edge_id); - if( m_edge_id_to_list_index_map.end() != remove_list_iterator ) { - const unsigned list_to_remove_index = remove_list_iterator->second; - BOOST_ASSERT( list_to_remove_index == GetPositionForID(removed_edge_id)); + BOOST_ASSERT( 0 < edge_bucket_list1.size() ); + BOOST_ASSERT( !edge_bucket_list1.empty() ); + + if( HasEntryForID(edge_id_2) ) { + // second edge is not atomic anymore + const unsigned list_to_remove_index = GetPositionForID(edge_id_2); BOOST_ASSERT( list_to_remove_index < m_compressed_geometries.size() ); - std::vector & remove_geometry_list = m_compressed_geometries[list_to_remove_index]; - if(surviving_edge_id == 0) { + std::vector & edge_bucket_list2 = m_compressed_geometries[list_to_remove_index]; + if( 0 == edge_id_1 ) { SimpleLogger().Write(logDEBUG) << "appending to list: "; - BOOST_FOREACH(const CompressedNode & node, remove_geometry_list) { + BOOST_FOREACH(const CompressedNode & node, edge_bucket_list2) { SimpleLogger().Write(logDEBUG) << "adding via " << node.first << ", w: " << node.second; } } - - // found an existing list, append it to the list of surviving_edge_id - surviving_geometry_list.insert( - surviving_geometry_list.end(), - remove_geometry_list.begin(), - remove_geometry_list.end() + // found an existing list, append it to the list of edge_id_1 + edge_bucket_list1.insert( + edge_bucket_list1.end(), + edge_bucket_list2.begin(), + edge_bucket_list2.end() ); - //remove the list of removed_edge_id - m_edge_id_to_list_index_map.erase(remove_list_iterator); - BOOST_ASSERT( m_edge_id_to_list_index_map.end() == m_edge_id_to_list_index_map.find(removed_edge_id) ); - remove_geometry_list.clear(); - BOOST_ASSERT( 0 == remove_geometry_list.size() ); + //remove the list of edge_id_2 + m_edge_id_to_list_index_map.erase(edge_id_2); + BOOST_ASSERT( m_edge_id_to_list_index_map.end() == m_edge_id_to_list_index_map.find(edge_id_2) ); + edge_bucket_list2.clear(); + BOOST_ASSERT( 0 == edge_bucket_list2.size() ); m_free_list.push_back(list_to_remove_index); BOOST_ASSERT( list_to_remove_index == m_free_list.back() ); + } else { + // we are certain that the second edge is atomic. + edge_bucket_list1.push_back( std::make_pair(target_node_id, weight2) ); } } diff --git a/Contractor/GeometryCompressor.h b/Contractor/GeometryCompressor.h index 1d2d60ea2..20f8a01aa 100644 --- a/Contractor/GeometryCompressor.h +++ b/Contractor/GeometryCompressor.h @@ -42,18 +42,19 @@ public: GeometryCompressor(); void CompressEdge( - const EdgeID first_edge_id, - const EdgeID second_edge_id, + const EdgeID surviving_edge_id, + const EdgeID removed_edge_id, const NodeID via_node_id, - const EdgeWeight weight1//, - // const EdgeWeight weight2 + const NodeID target_node, + const EdgeWeight weight1, + const EdgeWeight weight2 ); - void AddLastViaNodeIDToCompressedEdge( - const EdgeID edge_id, - const NodeID node_id, - const EdgeWeight weight - ); + // void AddLastViaNodeIDToCompressedEdge( + // const EdgeID edge_id, + // const NodeID node_id, + // const EdgeWeight weight + // ); bool HasEntryForID(const EdgeID edge_id) const; void PrintStatistics() const; void SerializeInternalVector(const std::string & path) const; From e68c750389db8db948130200fb3a81c1df0ad131 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 20 Feb 2014 19:04:13 +0100 Subject: [PATCH 12/89] remove boost typedefs --- typedefs.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/typedefs.h b/typedefs.h index a3a6362fe..b4fac11e7 100644 --- a/typedefs.h +++ b/typedefs.h @@ -28,9 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef TYPEDEFS_H_ #define TYPEDEFS_H_ -// To fix long and long long woes -#include -#include +#include // Necessary workaround for Windows as VS doesn't implement C99 #ifdef _MSC_VER @@ -46,9 +44,10 @@ digitT round(digitT x) { typedef unsigned int NodeID; typedef unsigned int EdgeID; -typedef unsigned int EdgeWeight; +typedef int EdgeWeight; -static const NodeID SPECIAL_NODEID = boost::integer_traits::const_max; -static const EdgeID SPECIAL_EDGEID = boost::integer_traits::const_max; +static const NodeID SPECIAL_NODEID = std::numeric_limits::max(); +static const EdgeID SPECIAL_EDGEID = std::numeric_limits::max(); +static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits::max(); #endif /* TYPEDEFS_H_ */ From 5bde545ce3ef9932d8e1fcd0c6180ad70212ec32 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Feb 2014 16:55:41 +0100 Subject: [PATCH 13/89] 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 { From b679a949305ba3d1fbc71cee8b2cec56614c359c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Feb 2014 15:55:04 +0100 Subject: [PATCH 14/89] first segment needs to be properly cut --- CMakeLists.txt | 2 +- Contractor/EdgeBasedGraphFactory.cpp | 65 +++++---- DataStructures/BinaryHeap.h | 10 ++ DataStructures/EdgeBasedNode.h | 112 ++++++++------- DataStructures/PhantomNodes.h | 11 +- DataStructures/QueryNode.h | 6 +- DataStructures/StaticRTree.h | 91 ++++++++---- Descriptors/DescriptionFactory.cpp | 4 +- RoutingAlgorithms/AlternativePathRouting.h | 154 +++++++++++++++------ RoutingAlgorithms/BasicRoutingInterface.h | 149 +++++++++++--------- RoutingAlgorithms/ShortestPathRouting.h | 7 + Server/DataStructures/InternalDataFacade.h | 20 +-- Server/DataStructures/SharedDataFacade.h | 20 ++- prepare.cpp | 40 +++--- 14 files changed, 435 insertions(+), 256 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e033134a6..021cbfe28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,7 +92,7 @@ endif() # Configuring compilers if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # using Clang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas -Wno-unneeded-internal-declaration -pedantic -fPIC") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunreachable-code -Wno-unknown-pragmas -Wno-unneeded-internal-declaration -pedantic -fPIC") message(STATUS "OpenMP parallelization not available using clang++") elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 279edf797..40c66a61f 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -223,8 +223,11 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges( void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & nodes) { #ifndef NDEBUG BOOST_FOREACH(const EdgeBasedNode & node, m_edge_based_node_list){ - BOOST_ASSERT(node.lat1 != INT_MAX); BOOST_ASSERT(node.lon1 != INT_MAX); - BOOST_ASSERT(node.lat2 != INT_MAX); BOOST_ASSERT(node.lon2 != INT_MAX); + + BOOST_ASSERT( m_node_info_list.at(node.u).lat != INT_MAX ); + BOOST_ASSERT( m_node_info_list.at(node.u).lon != INT_MAX ); + BOOST_ASSERT( m_node_info_list.at(node.v).lon != INT_MAX ); + BOOST_ASSERT( m_node_info_list.at(node.v).lat != INT_MAX ); } #endif nodes.swap(m_edge_based_node_list); @@ -443,13 +446,14 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); const unsigned geometry_size = forward_geometry.size(); - NodeID first_node_of_edge = u; + BOOST_ASSERT( geometry_size > 1 ); + NodeID current_edge_start_coordinate_id = u; // traverse arrays from start and end respectively for( unsigned i = 0; i < geometry_size; ++i ) { - BOOST_ASSERT( first_node_of_edge == reverse_geometry[geometry_size-1-i].first ); - const NodeID last_coordinate_id = forward_geometry[i].first; + BOOST_ASSERT( current_edge_start_coordinate_id == reverse_geometry[geometry_size-1-i].first ); + const NodeID current_edge_target_coordinate_id = forward_geometry[i].first; - // SimpleLogger().Write() << "adding edge (" << first_node_of_edge << "," << forward_geometry[i].first << ") "; + // SimpleLogger().Write() << "adding edge (" << current_edge_start_coordinate_id << "," << forward_geometry[i].first << ") "; // SimpleLogger().Write() << "fwd w: " << forward_geometry[i].second << ", fwd o: " << forward_dist_prefix_sum[i]; // SimpleLogger().Write() << "rev w: " << reverse_geometry[geometry_size-1-i].second << ", rev o: " << reverse_dist_prefix_sum[geometry_size-1-i]; @@ -458,30 +462,35 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( EdgeBasedNode( forward_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID, - m_node_info_list[first_node_of_edge].lat, - m_node_info_list[first_node_of_edge].lon, - m_node_info_list[forward_geometry[i].first].lat, - m_node_info_list[forward_geometry[i].first].lon, - belongs_to_tiny_cc,//TODO + current_edge_start_coordinate_id, + current_edge_target_coordinate_id, forward_data.nameID, forward_geometry[i].second, reverse_geometry[geometry_size-1-i].second, forward_dist_prefix_sum[i], - reverse_dist_prefix_sum[geometry_size-1-i] + reverse_dist_prefix_sum[geometry_size-1-i], + i, + geometry_size-1-i, + belongs_to_tiny_cc ) ); + current_edge_start_coordinate_id = current_edge_target_coordinate_id; + BOOST_ASSERT( m_edge_based_node_list.back().IsCompressed() ); - first_node_of_edge = last_coordinate_id; + + BOOST_ASSERT( + u != m_edge_based_node_list.back().u || + v != m_edge_based_node_list.back().v + ); + + BOOST_ASSERT( + u != m_edge_based_node_list.back().v || + v != m_edge_based_node_list.back().u + ); } //TODO: Manually reconstruct last edge. - - if( first_node_of_edge != v ) { - SimpleLogger().Write(logDEBUG) << "first_node_of_edge:" << first_node_of_edge << ", u: " << u << ", v: " << v; - } - - // BOOST_ASSERT( false ); - - BOOST_ASSERT( first_node_of_edge == v ); + BOOST_ASSERT( current_edge_start_coordinate_id == v ); + BOOST_ASSERT( m_edge_based_node_list.back().IsCompressed() ); } else { BOOST_ASSERT( !m_geometry_compressor.HasEntryForID(e2) ); @@ -507,16 +516,16 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( EdgeBasedNode( forward_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID, - m_node_info_list[u].lat, - m_node_info_list[u].lon, - m_node_info_list[v].lat, - m_node_info_list[v].lon, - belongs_to_tiny_cc, - forward_data.nameID, //TODO use also reverse name id? + u, + v, + forward_data.nameID, forward_data.distance, reverse_data.distance, 0, - 0 + 0, + 0, + 0, + belongs_to_tiny_cc ) ); BOOST_ASSERT( !m_edge_based_node_list.back().IsCompressed() ); diff --git a/DataStructures/BinaryHeap.h b/DataStructures/BinaryHeap.h index 9edd600e3..cc91272f1 100644 --- a/DataStructures/BinaryHeap.h +++ b/DataStructures/BinaryHeap.h @@ -96,6 +96,11 @@ public: return nodes[node]; } + Key const & operator[]( const NodeID node ) const { + UnorderedMapConstIterator iter = nodes.find(node); + return iter->second; + } + void Clear() { nodes.clear(); } @@ -158,6 +163,11 @@ public: return insertedNodes[index].data; } + Data const & GetData( NodeID node ) const { + const Key index = nodeIndex[node]; + return insertedNodes[index].data; + } + Weight& GetKey( NodeID node ) { const Key index = nodeIndex[node]; return insertedNodes[index].weight; diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index b8744edd3..fba3f39f5 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -13,67 +13,66 @@ struct EdgeBasedNode { EdgeBasedNode() : - id(INT_MAX), - reverse_edge_based_node_id(std::numeric_limits::max()), - lat1(std::numeric_limits::max()), - lon1(std::numeric_limits::max()), - lat2(std::numeric_limits::max()), - lon2(std::numeric_limits::max() >> 1), - belongsToTinyComponent(false), - name_id(std::numeric_limits::max()), + forward_edge_based_node_id(SPECIAL_NODEID), + reverse_edge_based_node_id(SPECIAL_NODEID), + u(SPECIAL_NODEID), + v(SPECIAL_NODEID), + name_id(0), forward_weight(std::numeric_limits::max() >> 1), reverse_weight(std::numeric_limits::max() >> 1), forward_offset(0), - reverse_offset(0) + reverse_offset(0), + fwd_segment_position( std::numeric_limits::max() ), + rev_segment_position( std::numeric_limits::max() >> 1 ), + belongsToTinyComponent(false) { } EdgeBasedNode( NodeID forward_edge_based_node_id, NodeID reverse_edge_based_node_id, - int lat1, - int lon1, - int lat2, - int lon2, - bool belongsToTinyComponent, - NodeID name_id, + NodeID u, + NodeID v, + unsigned name_id, int forward_weight, int reverse_weight, int forward_offset, - int reverse_offset + int reverse_offset, + unsigned short fwd_segment_position, + unsigned short rev_segment_position, + bool belongsToTinyComponent ) : forward_edge_based_node_id(forward_edge_based_node_id), reverse_edge_based_node_id(reverse_edge_based_node_id), - lat1(lat1), - lon1(lon1), - lat2(lat2), - lon2(lon2), - belongsToTinyComponent(belongsToTinyComponent), + u(u), + v(v), name_id(name_id), forward_weight(forward_weight), reverse_weight(reverse_weight), forward_offset(forward_offset), - reverse_offset(reverse_offset) + reverse_offset(reverse_offset), + fwd_segment_position(fwd_segment_position), + rev_segment_position(rev_segment_position), + belongsToTinyComponent(belongsToTinyComponent) { } - // Computes: // - the distance from the given query location to nearest point on this edge (and returns it) - // - the location on this edge which is nearest to the query location - // - the ratio ps:pq, where p and q are the end points of this edge, and s is the perpendicular foot of + inline static double ComputePerpendicularDistance( + const FixedPointCoordinate & coord_a, + const FixedPointCoordinate & coord_b, // the query location on the line defined by p and q. double ComputePerpendicularDistance( - const FixedPointCoordinate& query_location, + const FixedPointCoordinate & query_location, FixedPointCoordinate & nearest_location, - double & ratio, - double precision = COORDINATE_PRECISION - ) const { + double & r + ) { BOOST_ASSERT( query_location.isValid() ); const double epsilon = 1.0/precision; const double y = query_location.lon/COORDINATE_PRECISION; - const double a = lat2y(lat1/COORDINATE_PRECISION); - const double b = lon1/COORDINATE_PRECISION; - const double c = lat2y(lat2/COORDINATE_PRECISION); - const double d = lon2/COORDINATE_PRECISION; + const double a = lat2y(coord_a.lat/COORDINATE_PRECISION); + const double b = coord_a.lon/COORDINATE_PRECISION; + const double c = lat2y(coord_b.lat/COORDINATE_PRECISION); + const double d = coord_b.lon/COORDINATE_PRECISION; double p,q/*,mX*/,nY; if( std::abs(a-c) > std::numeric_limits::epsilon() ){ const double m = (d-b)/(c-a); // slope @@ -92,18 +91,20 @@ struct EdgeBasedNode { } // p, q : the end points of the underlying edge - const Point p(lat2y(lat1/COORDINATE_PRECISION), lon1/COORDINATE_PRECISION); - const Point q(lat2y(lat2/COORDINATE_PRECISION), lon2/COORDINATE_PRECISION); + if( std::isnan(r) ) { + r = ((coord_b.lat == query_location.lat) && (coord_b.lon == query_location.lon)) ? 1. : 0.; // r : query location const Point r(lat2y(query_location.lat/COORDINATE_PRECISION), } else if( std::abs(r-1.) <= std::numeric_limits::epsilon() ) { query_location.lon/COORDINATE_PRECISION); - - const Point foot = ComputePerpendicularFoot(p, q, r, epsilon); - ratio = ComputeRatio(p, q, foot, epsilon); - - BOOST_ASSERT( !std::isnan(ratio) ); + nearest_location.lat = coord_a.lat; + nearest_location.lon = coord_a.lon; + } else if( r >= 1. ){ + nearest_location.lat = coord_b.lat; + nearest_location.lon = coord_b.lon; + } else { + // point lies in between nearest_location.lat = y2lat(p)*COORDINATE_PRECISION; nearest_location = ComputeNearestPointOnSegment(foot, ratio); @@ -120,12 +121,20 @@ struct EdgeBasedNode { return approximated_distance; } - bool operator<(const EdgeBasedNode & other) const { + static inline FixedPointCoordinate Centroid( + const FixedPointCoordinate & a, + const FixedPointCoordinate & b + ) { return other.id < id; + //The coordinates of the midpoint are given by: + //x = (x1 + x2) /2 and y = (y1 + y2) /2. + centroid.lon = (std::min(a.lon, b.lon) + std::max(a.lon, b.lon))/2; + centroid.lat = (std::min(a.lat, b.lat) + std::max(a.lat, b.lat))/2; + return centroid; } - bool operator==(const EdgeBasedNode & other) const { - return id == other.id; + bool IsCompressed() { + return (fwd_segment_position + rev_segment_position) != 0; } // Returns the midpoint of the underlying edge. @@ -134,13 +143,16 @@ struct EdgeBasedNode { } NodeID forward_edge_based_node_id; - - // The coordinates of the end-points of the underlying edge. - int lat1; - int lon1; - int lat2; - int lon2:31; - + NodeID reverse_edge_based_node_id; + NodeID u; + NodeID v; + unsigned name_id; + int forward_weight; + int reverse_weight; + int forward_offset; + int reverse_offset; + unsigned short fwd_segment_position; + unsigned short rev_segment_position:15; bool belongsToTinyComponent:1; NodeID name_id; diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index e01774691..9ce918750 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -40,7 +40,9 @@ struct PhantomNode { reverse_weight(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0), - ratio(0.) + ratio(0.), + fwd_segment_position(0), + rev_segment_position(0) { } NodeID forward_node_id; @@ -52,6 +54,9 @@ struct PhantomNode { int reverse_offset; double ratio; FixedPointCoordinate location; + unsigned short fwd_segment_position; + unsigned short rev_segment_position; + int GetForwardWeightPlusOffset() const { return forward_weight + forward_offset; @@ -108,8 +113,10 @@ struct PhantomNodes { return (startPhantom.forward_node_id == targetPhantom.forward_node_id); } + + //TODO: Rename to: BothPhantomNodesAreInvalid bool AtLeastOnePhantomNodeIsUINTMAX() const { - return !(startPhantom.forward_node_id == SPECIAL_NODEID || targetPhantom.forward_node_id == SPECIAL_NODEID); + return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.forward_node_id == SPECIAL_NODEID); } bool PhantomNodesHaveEqualLocation() const { diff --git a/DataStructures/QueryNode.h b/DataStructures/QueryNode.h index 22a440415..916aa50e2 100644 --- a/DataStructures/QueryNode.h +++ b/DataStructures/QueryNode.h @@ -72,13 +72,11 @@ struct NodeInfo { switch(n) { case 1: return lat; - break; + // break; case 0: return lon; - break; + // break; default: - BOOST_ASSERT_MSG(false, "should not happen"); - return std::numeric_limits::max(); break; } BOOST_ASSERT_MSG(false, "should not happen"); diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index aef5544b1..9e62cd663 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "DeallocatingVector.h" #include "HilbertValue.h" #include "PhantomNodes.h" +#include "QueryNode.h" #include "SharedMemoryFactory.h" #include "SharedMemoryVectorWrapper.h" @@ -84,21 +85,34 @@ public: inline void InitializeMBRectangle( DataT const * objects, - const uint32_t element_count + const uint32_t element_count, + const std::vector & coordinate_list ) { for(uint32_t i = 0; i < element_count; ++i) { min_lon = std::min( - min_lon, std::min(objects[i].lon1, objects[i].lon2) + min_lon, std::min( + coordinate_list.at(objects[i].u).lon, + coordinate_list.at(objects[i].v).lon + ) ); max_lon = std::max( - max_lon, std::max(objects[i].lon1, objects[i].lon2) + max_lon, std::max( + coordinate_list.at(objects[i].u).lon, + coordinate_list.at(objects[i].v).lon + ) ); min_lat = std::min( - min_lat, std::min(objects[i].lat1, objects[i].lat2) + min_lat, std::min( + coordinate_list.at(objects[i].u).lat, + coordinate_list.at(objects[i].v).lon + ) ); max_lat = std::max( - max_lat, std::max(objects[i].lat1, objects[i].lat2) + max_lat, std::max( + coordinate_list.at(objects[i].u).lat, + coordinate_list.at(objects[i].v).lon + ) ); } } @@ -298,14 +312,15 @@ public: explicit StaticRTree( std::vector & input_data_vector, const std::string tree_node_filename, - const std::string leaf_node_filename + const std::string leaf_node_filename, + const std::vector & coordinate_list ) : m_element_count(input_data_vector.size()), m_leaf_node_filename(leaf_node_filename) { SimpleLogger().Write() << "constructing r-tree of " << m_element_count << - " elements"; + " edge elements build on-top of " << coordinate_list.size() << " coordinates"; double time1 = get_timestamp(); std::vector input_wrapper_vector(m_element_count); @@ -318,7 +333,16 @@ public: input_wrapper_vector[element_counter].m_array_index = element_counter; //Get Hilbert-Value for centroid in mercartor projection DataT const & current_element = input_data_vector[element_counter]; - FixedPointCoordinate current_centroid = current_element.Centroid(); + FixedPointCoordinate current_centroid = DataT::Centroid( + FixedPointCoordinate( + coordinate_list.at(current_element.u).lat, + coordinate_list.at(current_element.u).lon + ), + FixedPointCoordinate( + coordinate_list.at(current_element.v).lat, + coordinate_list.at(current_element.v).lon + ) + ); current_centroid.lat = COORDINATE_PRECISION*lat2y(current_centroid.lat/COORDINATE_PRECISION); uint64_t current_hilbert_value = get_hilbert_number(current_centroid); @@ -349,7 +373,11 @@ public: } //generate tree node that resemble the objects in leaf and store it for next level - current_node.minimum_bounding_rectangle.InitializeMBRectangle(current_leaf.objects, current_leaf.object_count); + current_node.minimum_bounding_rectangle.InitializeMBRectangle( + current_leaf.objects, + current_leaf.object_count, + coordinate_list + ); current_node.child_is_on_disk = true; current_node.children[0] = tree_nodes_in_level.size(); tree_nodes_in_level.push_back(current_node); @@ -543,29 +571,29 @@ public: double current_minimum_distance = FixedPointCoordinate::ApproximateDistance( input_coordinate.lat, input_coordinate.lon, - current_edge.lat1, - current_edge.lon1 + m_coordinate_list->at(current_edge.u).lat, + m_coordinate_list->at(current_edge.u).lon ); if( current_minimum_distance < min_dist ) { //found a new minimum min_dist = current_minimum_distance; - result_coordinate.lat = current_edge.lat1; - result_coordinate.lon = current_edge.lon1; + result_coordinate.lat = m_coordinate_list->at(current_edge.u).lat; + result_coordinate.lon = m_coordinate_list->at(current_edge.u).lon; found_a_nearest_edge = true; } current_minimum_distance = FixedPointCoordinate::ApproximateDistance( input_coordinate.lat, input_coordinate.lon, - current_edge.lat2, - current_edge.lon2 + m_coordinate_list->at(current_edge.v).lat, + m_coordinate_list->at(current_edge.v).lon ); if( current_minimum_distance < min_dist ) { //found a new minimum min_dist = current_minimum_distance; - result_coordinate.lat = current_edge.lat2; - result_coordinate.lon = current_edge.lon2; + result_coordinate.lat = m_coordinate_list->at(current_edge.v).lat; + result_coordinate.lon = m_coordinate_list->at(current_edge.v).lon; found_a_nearest_edge = true; } } @@ -645,6 +673,8 @@ public: double current_ratio = 0.; double current_perpendicular_distance = current_edge.ComputePerpendicularDistance( + m_coordinate_list->at(current_edge.u), + m_coordinate_list->at(current_edge.v), input_coordinate, nearest, current_ratio @@ -653,25 +683,27 @@ public: BOOST_ASSERT( 0. <= current_perpendicular_distance ); if( - ( current_perpendicular_distance < min_dist ) && - !DoubleEpsilonCompare( - current_perpendicular_distance, - min_dist - ) + ( current_perpendicular_distance < min_dist ) //&& + // !DoubleEpsilonCompare( + // current_perpendicular_distance, + // min_dist + // ) ) { //found a new minimum min_dist = current_perpendicular_distance; result_phantom_node.forward_node_id = current_edge.forward_edge_based_node_id; result_phantom_node.reverse_node_id = current_edge.reverse_edge_based_node_id; - 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.fwd_segment_position = current_edge.fwd_segment_position; + result_phantom_node.rev_segment_position = current_edge.rev_segment_position; + result_phantom_node.name_id = current_edge.name_id; result_phantom_node.location = nearest; - current_start_coordinate.lat = current_edge.lat1; - current_start_coordinate.lon = current_edge.lon1; - current_end_coordinate.lat = current_edge.lat2; - current_end_coordinate.lon = current_edge.lon2; + current_start_coordinate.lat = m_coordinate_list->at(current_edge.u).lat; + current_start_coordinate.lon = m_coordinate_list->at(current_edge.u).lon; + current_end_coordinate.lat = m_coordinate_list->at(current_edge.v).lat; + current_end_coordinate.lon = m_coordinate_list->at(current_edge.v).lon; nearest_edge = current_edge; found_a_nearest_edge = true; } @@ -730,10 +762,11 @@ public: } result_phantom_node.ratio = ratio; - SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location; + SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight << ", ratio: " << result_phantom_node.ratio; - + SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); + SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id; return found_a_nearest_edge; } diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 11dfc1164..2b2842282 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -140,8 +140,8 @@ 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; + // 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/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index e9e771ea8..86e35d8b9 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -76,15 +76,16 @@ public: ~AlternativeRouting() {} - void operator()( + void operator() ( const PhantomNodes & phantom_node_pair, RawRouteData & raw_route_data ) { - if( (!phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX()) || - phantom_node_pair.PhantomNodesHaveEqualLocation() + if( //phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() || + phantom_node_pair.PhantomNodesHaveEqualLocation() ) { raw_route_data.lengthOfShortestPath = INT_MAX; raw_route_data.lengthOfAlternativePath = INT_MAX; + SimpleLogger().Write(logDEBUG) << "not executing path search"; return; } @@ -109,14 +110,18 @@ public: QueryHeap & forward_heap2 = *(engine_working_data.forwardHeap2); QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2); - int upper_bound_to_shortest_path_distance = INT_MAX; + int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT; NodeID middle_node = UINT_MAX; - forward_heap1.Insert( - phantom_node_pair.startPhantom.forward_node_id, - -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.startPhantom.forward_node_id - ); - if(phantom_node_pair.startPhantom.isBidirected() ) { + if(phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id; + forward_heap1.Insert( + phantom_node_pair.startPhantom.forward_node_id, + -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), + phantom_node_pair.startPhantom.forward_node_id + ); + } + if(phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.reverse_node_id; forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), @@ -124,12 +129,16 @@ public: ); } - reverse_heap1.Insert( - phantom_node_pair.targetPhantom.forward_node_id, - phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.targetPhantom.forward_node_id - ); - if(phantom_node_pair.targetPhantom.isBidirected() ) { + if(phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id; + reverse_heap1.Insert( + phantom_node_pair.targetPhantom.forward_node_id, + phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), + phantom_node_pair.targetPhantom.forward_node_id + ); + } + if(phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id; reverse_heap1.Insert( phantom_node_pair.targetPhantom.reverse_node_id, phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), @@ -237,16 +246,16 @@ public: } } - std::vector & packedShortestPath = packed_forward_path; - std::reverse(packedShortestPath.begin(), packedShortestPath.end()); - packedShortestPath.push_back(middle_node); - packedShortestPath.insert(packedShortestPath.end(),packed_reverse_path.begin(), packed_reverse_path.end()); + std::vector & packed_shortest_path = packed_forward_path; + std::reverse(packed_shortest_path.begin(), packed_shortest_path.end()); + packed_shortest_path.push_back(middle_node); + packed_shortest_path.insert(packed_shortest_path.end(),packed_reverse_path.begin(), packed_reverse_path.end()); std::vector rankedCandidates; //prioritizing via nodes for deep inspection BOOST_FOREACH(const NodeID node, nodes_that_passed_preselection) { int lengthOfViaPath = 0, sharingOfViaPath = 0; - computeLengthAndSharingOfViaPath(node, &lengthOfViaPath, &sharingOfViaPath, forward_offset+reverse_offset, packedShortestPath); + computeLengthAndSharingOfViaPath(node, &lengthOfViaPath, &sharingOfViaPath, forward_offset+reverse_offset, packed_shortest_path); if(sharingOfViaPath <= upper_bound_to_shortest_path_distance*VIAPATH_GAMMA) { rankedCandidates.push_back(RankedCandidateNode(node, lengthOfViaPath, sharingOfViaPath)); } @@ -267,33 +276,92 @@ public: //Unpack shortest path and alternative, if they exist if(INT_MAX != upper_bound_to_shortest_path_distance) { + BOOST_ASSERT( !packed_shortest_path.empty() ); raw_route_data.unpacked_path_segments.resize(1); - super::UnpackPath(packedShortestPath, raw_route_data.unpacked_path_segments[0]); + // SimpleLogger().Write() << "fwd offset1: " << phantom_node_pair.startPhantom.fwd_segment_position; + // SimpleLogger().Write() << "fwd offset2: " << phantom_node_pair.startPhantom.rev_segment_position; + // SimpleLogger().Write() << "rev offset1: " << phantom_node_pair.targetPhantom.fwd_segment_position; + // SimpleLogger().Write() << "rev offset2: " << phantom_node_pair.targetPhantom.rev_segment_position; + + // int start_offset = ( packed_shortest_path.front() == phantom_node_pair.startPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.startPhantom.fwd_segment_position; + // SimpleLogger().Write(logDEBUG) << "unpacking from index " << phantom_node_pair.startPhantom.fwd_segment_position; + + SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.forward_node_id: " << phantom_node_pair.startPhantom.forward_node_id; + SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.reverse_node_id: " << phantom_node_pair.startPhantom.reverse_node_id; + SimpleLogger().Write(logDEBUG) << "packed_shortest_path.front(): " << packed_shortest_path.front(); + // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); + + super::UnpackPath( + packed_shortest_path, + phantom_node_pair.startPhantom.fwd_segment_position, + (packed_shortest_path.front() == phantom_node_pair.startPhantom.reverse_node_id), + phantom_node_pair.targetPhantom.fwd_segment_position,//( packed_forward_path.back() == phantom_node_pair.targetPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.targetPhantom.fwd_segment_position, + raw_route_data.unpacked_path_segments.front() + ); raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; } else { + //TODO: kill this branch by initialization 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, raw_route_data.unpacked_alternative); + RetrieveAndUnpackAlternatePath( + forward_heap1, + reverse_heap1, + forward_heap2, + reverse_heap2, + s_v_middle, + v_t_middle, + raw_route_data.unpacked_alternative + ); raw_route_data.lengthOfAlternativePath = lengthOfViaPath; } else { + //TODO: kill this branch by initialization raw_route_data.lengthOfAlternativePath = INT_MAX; } } private: //unpack by exploring search spaces from v - inline void retrievePackedViaPath(QueryHeap & _forwardHeap1, QueryHeap & _backwardHeap1, QueryHeap & _forwardHeap2, QueryHeap & _backwardHeap2, - const NodeID s_v_middle, const NodeID v_t_middle, std::vector & unpackedPath) { - //unpack [s,v) + inline void RetrieveAndUnpackAlternatePath( + const QueryHeap & forward_heap1, + const QueryHeap & reverse_heap1, + const QueryHeap & forward_heap2, + const QueryHeap & reverse_heap2, + const NodeID s_v_middle, + const NodeID v_t_middle, + std::vector & unpacked_path + ) const { + //fetch packed path [s,v) std::vector packed_s_v_path, packed_v_t_path; - super::RetrievePackedPathFromHeap(_forwardHeap1, _backwardHeap2, s_v_middle, packed_s_v_path); - packed_s_v_path.resize(packed_s_v_path.size()-1); - //unpack [v,t] - super::RetrievePackedPathFromHeap(_forwardHeap2, _backwardHeap1, v_t_middle, packed_v_t_path); - packed_s_v_path.insert(packed_s_v_path.end(),packed_v_t_path.begin(), packed_v_t_path.end() ); - super::UnpackPath(packed_s_v_path, unpackedPath); + super::RetrievePackedPathFromHeap( + forward_heap1, + reverse_heap2, + s_v_middle, + packed_s_v_path + ); + packed_s_v_path.pop_back(); //remove v, other we get it twice + + //fetch patched path [v,t] + super::RetrievePackedPathFromHeap( + forward_heap2, + reverse_heap1, + v_t_middle, + packed_v_t_path + ); + + packed_s_v_path.insert( + packed_s_v_path.end(), + packed_v_t_path.begin(), + packed_v_t_path.end() + ); + + // unpack, supply correct offsets to packed start and end nodes. + super::UnpackPath( + packed_s_v_path, + 0, false, 0, //TODO: replace by real offsets + unpacked_path + ); } inline void computeLengthAndSharingOfViaPath(const NodeID via_node, int *real_length_of_via_path, int *sharing_of_via_path, @@ -312,7 +380,7 @@ private: std::vector < NodeID > packed_s_v_path; std::vector < NodeID > packed_v_t_path; - std::vector partiallyUnpackedShortestPath; + std::vector partiallyUnpacked_shortest_path; std::vector partiallyUnpackedViaPath; NodeID s_v_middle = UINT_MAX; @@ -346,13 +414,13 @@ private: } 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); - super::UnpackEdge(packed_shortest_path[i], packed_shortest_path[i+1], partiallyUnpackedShortestPath); + super::UnpackEdge(packed_shortest_path[i], packed_shortest_path[i+1], partiallyUnpacked_shortest_path); break; } } } //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) { + for (int i = 0, lengthOfPackedPath = std::min( partiallyUnpackedViaPath.size(), partiallyUnpacked_shortest_path.size()) - 1; (i < lengthOfPackedPath) && (partiallyUnpackedViaPath[i] == partiallyUnpacked_shortest_path[i] && partiallyUnpackedViaPath[i+1] == partiallyUnpacked_shortest_path[i+1]); ++i) { EdgeID edgeID = facade->FindEdgeInEitherDirection(partiallyUnpackedViaPath[i], partiallyUnpackedViaPath[i+1]); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } @@ -367,16 +435,16 @@ private: } 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); - super::UnpackEdge(packed_shortest_path[shortestPathIndex-1] , packed_shortest_path[shortestPathIndex], partiallyUnpackedShortestPath); + super::UnpackEdge(packed_shortest_path[shortestPathIndex-1] , packed_shortest_path[shortestPathIndex], partiallyUnpacked_shortest_path); break; } } } viaPathIndex = partiallyUnpackedViaPath.size() - 1; - shortestPathIndex = partiallyUnpackedShortestPath.size() - 1; + shortestPathIndex = partiallyUnpacked_shortest_path.size() - 1; for (; viaPathIndex > 0 && shortestPathIndex > 0; --viaPathIndex,--shortestPathIndex) { - if (partiallyUnpackedViaPath[viaPathIndex - 1] == partiallyUnpackedShortestPath[shortestPathIndex - 1] && partiallyUnpackedViaPath[viaPathIndex] == partiallyUnpackedShortestPath[shortestPathIndex]) { + if (partiallyUnpackedViaPath[viaPathIndex - 1] == partiallyUnpacked_shortest_path[shortestPathIndex - 1] && partiallyUnpackedViaPath[viaPathIndex] == partiallyUnpacked_shortest_path[shortestPathIndex]) { EdgeID edgeID = facade->FindEdgeInEitherDirection( partiallyUnpackedViaPath[viaPathIndex - 1], partiallyUnpackedViaPath[viaPathIndex]); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { @@ -386,17 +454,17 @@ private: //finished partial unpacking spree! Amount of sharing is stored to appropriate pointer variable } - inline int approximateAmountOfSharing(const NodeID middleNodeIDOfAlternativePath, QueryHeap & _forwardHeap, QueryHeap & _backwardHeap, const std::vector & packedShortestPath) { + inline int approximateAmountOfSharing(const NodeID middleNodeIDOfAlternativePath, QueryHeap & _forwardHeap, QueryHeap & _backwardHeap, const std::vector & packed_shortest_path) { std::vector packedAlternativePath; super::RetrievePackedPathFromHeap(_forwardHeap, _backwardHeap, middleNodeIDOfAlternativePath, packedAlternativePath); - if(packedShortestPath.size() < 2 || packedAlternativePath.size() < 2) + if(packed_shortest_path.size() < 2 || packedAlternativePath.size() < 2) return 0; int sharing = 0; int aindex = 0; //compute forward sharing - while( (packedAlternativePath[aindex] == packedShortestPath[aindex]) && (packedAlternativePath[aindex+1] == packedShortestPath[aindex+1]) ) { + while( (packedAlternativePath[aindex] == packed_shortest_path[aindex]) && (packedAlternativePath[aindex+1] == packed_shortest_path[aindex+1]) ) { // SimpleLogger().Write() << "retrieving edge (" << packedAlternativePath[aindex] << "," << packedAlternativePath[aindex+1] << ")"; EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); sharing += facade->GetEdgeData(edgeID).distance; @@ -404,9 +472,9 @@ private: } aindex = packedAlternativePath.size()-1; - int bindex = packedShortestPath.size()-1; + int bindex = packed_shortest_path.size()-1; //compute backward sharing - while( aindex > 0 && bindex > 0 && (packedAlternativePath[aindex] == packedShortestPath[bindex]) && (packedAlternativePath[aindex-1] == packedShortestPath[bindex-1]) ) { + while( aindex > 0 && bindex > 0 && (packedAlternativePath[aindex] == packed_shortest_path[bindex]) && (packedAlternativePath[aindex-1] == packed_shortest_path[bindex-1]) ) { EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex-1]); sharing += facade->GetEdgeData(edgeID).distance; --aindex; --bindex; diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 66db0409e..224e53a10 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -138,8 +138,24 @@ public: inline void UnpackPath( const std::vector & packed_path, + int fwd_index_offset, + bool start_traversed_in_reverse, + int rev_index_offset, std::vector & unpacked_path ) const { + + // SimpleLogger().Write(logDEBUG) << "unpacking path"; + // for(unsigned i = 0; i < packed_path.size(); ++i) { + // std::cout << packed_path[i] << " "; + // } + + bool segment_reversed = false; + + SimpleLogger().Write(logDEBUG) << "fwd offset: " << fwd_index_offset; + SimpleLogger().Write(logDEBUG) << "rev offset: " << rev_index_offset; + SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << ( start_traversed_in_reverse ? "y" : "n" ); + + // SimpleLogger().Write() << "starting unpack"; const unsigned packed_path_size = packed_path.size(); std::stack > recursion_stack; @@ -155,42 +171,13 @@ public: edge = recursion_stack.top(); recursion_stack.pop(); - EdgeID smaller_edge_id = SPECIAL_EDGEID; - int edge_weight = INT_MAX; - 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(edge_id) == edge.second) && - (weight < edge_weight) && - facade->GetEdgeData(edge_id).forward - ){ - smaller_edge_id = edge_id; - edge_weight = weight; - } - } + EdgeID smaller_edge_id = facade->FindEdgeIndicateIfReverse( + edge.first, + edge.second, + segment_reversed + ); - if( SPECIAL_EDGEID == smaller_edge_id ){ - 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(edge_id) == edge.first) && - (weight < edge_weight) && - facade->GetEdgeData(edge_id).backward - ){ - smaller_edge_id = edge_id; - edge_weight = weight; - } - } - } - BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid"); + BOOST_ASSERT( SPECIAL_EDGEID != smaller_edge_id ); const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if( ed.shortcut ) {//unpack @@ -201,11 +188,10 @@ public: } else { BOOST_ASSERT_MSG(!ed.shortcut, "original edge flagged as shortcut"); unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id); - TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); + const TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); //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) ); unpacked_path.push_back( PathData( @@ -216,38 +202,74 @@ public: ) ); } else { - SimpleLogger().Write() << "Edge " << ed.id << " is compressed"; std::vector id_vector; facade->GetUncompressedGeometry(ed.id, id_vector); + + + //TODO use only a single for loop if( unpacked_path.empty() ) { - SimpleLogger().Write(logDEBUG) << "first segment(" << facade->GetEscapedNameForNameID(ed.id) << ") is packed"; + // // SimpleLogger().Write(logDEBUG) << "1st node in packed path: " << packed_path.front() << ", edge (" << edge.first << "," << edge.second << ")"; + // // SimpleLogger().Write(logDEBUG) << "REVERSED1: " << ( facade->GetTarget(smaller_edge_id) != edge.second ? "y" : "n" ); + // // SimpleLogger().Write(logDEBUG) << "REVERSED2: " << ( facade->GetTarget(smaller_edge_id) != edge.first ? "y" : "n" ); + // SimpleLogger().Write(logDEBUG) << "segment_reversed: " << ( segment_reversed ? "y" : "n" ); + // // SimpleLogger().Write(logDEBUG) << "target of edge: " << facade->GetTarget(smaller_edge_id); + // // SimpleLogger().Write(logDEBUG) << "first geometry: " << id_vector.front() << ", last geometry: " << id_vector.back(); + const bool edge_is_reversed = (!ed.forward && ed.backward); + + // if( edge_is_reversed ) { + // SimpleLogger().Write(logDEBUG) << "reversing geometry"; + // std::reverse( id_vector.begin(), id_vector.end() ); + // fwd_index_offset = id_vector.size() - (1+fwd_index_offset); + // SimpleLogger().Write() << "new fwd offset: " << fwd_index_offset; + // } + + SimpleLogger().Write(logDEBUG) << "edge data fwd: " << (ed.forward ? "y": "n") << ", reverse: " << (ed.backward ? "y" : "n" ); + SimpleLogger().Write() << "Edge " << ed.id << "=(" << edge.first << "," << edge.second << ") is compressed"; + SimpleLogger().Write(logDEBUG) << "packed ids: "; + BOOST_FOREACH(unsigned number, id_vector) { + SimpleLogger().Write() << "[" << number << "] " << facade->GetCoordinateOfNode(number); + } + const int start_index = ( ( start_traversed_in_reverse ) ? fwd_index_offset : 0 ); + const int end_index = ( ( start_traversed_in_reverse ) ? id_vector.size() : fwd_index_offset ); + + // BOOST_ASSERT( start_index >= 0 ); + // // BOOST_ASSERT( start_index <= end_index ); + SimpleLogger().Write(logDEBUG) << "geometry count: " << id_vector.size() << ", fetching[" << start_index << "..." << end_index << "]"; + for( + unsigned i = start_index; + i != end_index; + (start_index > end_index) ? --i : ++i + ) { + SimpleLogger().Write(logDEBUG) << "[" << i << "]pushing id: " << id_vector[i]; + unpacked_path.push_back( + PathData( + id_vector[i], + name_index, + TurnInstructionsClass::NoTurn, + 0 + ) + ); + } + } else { + BOOST_FOREACH(const unsigned coordinate_id, id_vector){ + // SimpleLogger().Write(logDEBUG) << "pushing id: " << coordinate_id; + unpacked_path.push_back( + PathData( + coordinate_id, + name_index, + TurnInstructionsClass::NoTurn, + 0 + ) + ); + + } + unpacked_path.back().turnInstruction = turn_instruction; + unpacked_path.back().durationOfSegment = ed.distance; } - - // 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, - name_index, - TurnInstructionsClass::NoTurn, - 0 - ) - ); - - } - unpacked_path.back().turnInstruction = turn_instruction; - unpacked_path.back().durationOfSegment = ed.distance; } - } } - - } inline void UnpackEdge( @@ -319,8 +341,8 @@ public: } inline void RetrievePackedPathFromHeap( - SearchEngineData::QueryHeap & forward_heap, - SearchEngineData::QueryHeap & reverse_heap, + const SearchEngineData::QueryHeap & forward_heap, + const SearchEngineData::QueryHeap & reverse_heap, const NodeID middle_node_id, std::vector & packed_path ) const { @@ -329,6 +351,7 @@ public: current_node_id = forward_heap.GetData(current_node_id).parent; packed_path.push_back(current_node_id); } + //throw away first segment, unpack individually std::reverse(packed_path.begin(), packed_path.end()); packed_path.push_back(middle_node_id); diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 5e90af97b..a711c91a0 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -356,10 +356,17 @@ public: std::swap( packed_legs1, packed_legs2 ); } raw_route_data.unpacked_path_segments.resize( packed_legs1.size() ); + const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().startPhantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().startPhantom.fwd_segment_position; + for(unsigned i = 0; i < packed_legs1.size(); ++i){ + BOOST_ASSERT( !phantom_nodes_vector.empty() ); + bool at_beginning = (0 == i); BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); super::UnpackPath( packed_legs1[i], + ( at_beginning ? start_offset : 0), + 0, + false, raw_route_data.unpacked_path_segments[i] ); } diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index a10517cfd..5ff639df5 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -428,11 +428,13 @@ public: PhantomNode & resulting_phantom_node, const unsigned zoom_level ) const { - return m_static_rtree->FindPhantomNodeForCoordinate( - input_coordinate, - resulting_phantom_node, - zoom_level - ); + // SimpleLogger().Write(logDEBUG) << "name id: " << resulting_phantom_node.name_id; + const bool found = m_static_rtree->FindPhantomNodeForCoordinate( + input_coordinate, + resulting_phantom_node, + zoom_level + ); + return found; } unsigned GetCheckSum() const { return m_check_sum; } @@ -479,17 +481,17 @@ public: const unsigned id, std::vector & result_nodes ) const { const NodeID node = m_via_node_list.at(id); - SimpleLogger().Write() << "translated " << id << " to " << node; - SimpleLogger().Write() << "getting geometry from compression bucket " << node << "/" << m_compressed_geometry_indices.size(); + // SimpleLogger().Write() << "translated " << id << " to " << node; + // SimpleLogger().Write() << "getting geometry from compression bucket " << node << "/" << m_compressed_geometry_indices.size(); unsigned begin = m_compressed_geometry_indices.at(node); unsigned end = m_compressed_geometry_indices.at(node+1); - SimpleLogger().Write() << "bucket " << node << " has range [" << begin << "," << end-1 << "]"; + // SimpleLogger().Write() << "bucket " << node << " has range [" << begin << "," << end-1 << "]"; //TODO: use vector.insert(.) for(unsigned geometry_index = begin; geometry_index < end; ++geometry_index) { 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 be86d4221..33ce972bc 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -363,11 +363,21 @@ public: PhantomNode & resulting_phantom_node, const unsigned zoom_level ) const { - return m_static_rtree->FindPhantomNodeForCoordinate( - input_coordinate, - resulting_phantom_node, - zoom_level - ); + const bool found = m_static_rtree->FindPhantomNodeForCoordinate( + input_coordinate, + resulting_phantom_node, + zoom_level + ); + + if ( found ) { + resulting_phantom_node.name_id = GetNameIndexFromEdgeID( + FindEdge( + resulting_phantom_node.forward_node_id, + resulting_phantom_node.reverse_node_id + ) + ); + } + return found; } unsigned GetCheckSum() const { return m_check_sum; } diff --git a/prepare.cpp b/prepare.cpp index c56b6a91f..fcf1fd077 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -269,6 +269,26 @@ int main (int argc, char *argv[]) { edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); delete edgeBasedGraphFactory; + double expansionHasFinishedTime = get_timestamp() - startupTime; + /*** + * Building grid-like nearest-neighbor data structure + */ + + SimpleLogger().Write() << "building r-tree ..."; + StaticRTree * rtree = + new StaticRTree( + nodeBasedEdgeList, + rtree_nodes_path.c_str(), + rtree_leafs_path.c_str(), + internalToExternalNodeMapping + ); + delete rtree; + IteratorbasedCRC32 > crc32; + unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); + nodeBasedEdgeList.clear(); + std::vector(nodeBasedEdgeList).swap(nodeBasedEdgeList); + SimpleLogger().Write() << "CRC32: " << crc32OfNodeBasedEdgeList; + /*** * Writing info on original (node-based) nodes */ @@ -284,26 +304,6 @@ int main (int argc, char *argv[]) { mapOutFile.close(); std::vector().swap(internalToExternalNodeMapping); - double expansionHasFinishedTime = get_timestamp() - startupTime; - - /*** - * Building grid-like nearest-neighbor data structure - */ - - SimpleLogger().Write() << "building r-tree ..."; - StaticRTree * rtree = - new StaticRTree( - nodeBasedEdgeList, - rtree_nodes_path.c_str(), - rtree_leafs_path.c_str() - ); - delete rtree; - IteratorbasedCRC32 > crc32; - unsigned crc32OfNodeBasedEdgeList = crc32(nodeBasedEdgeList.begin(), nodeBasedEdgeList.end() ); - nodeBasedEdgeList.clear(); - std::vector(nodeBasedEdgeList).swap(nodeBasedEdgeList); - SimpleLogger().Write() << "CRC32: " << crc32OfNodeBasedEdgeList; - /*** * Contracting the edge-expanded graph */ From a0bddab1690c74034560deb2e059996478898ad7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Feb 2014 18:44:34 +0100 Subject: [PATCH 15/89] 3/4 unpack cases working --- RoutingAlgorithms/AlternativePathRouting.h | 2 +- RoutingAlgorithms/BasicRoutingInterface.h | 24 ++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 86e35d8b9..b9d7943d1 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -294,7 +294,7 @@ public: super::UnpackPath( packed_shortest_path, phantom_node_pair.startPhantom.fwd_segment_position, - (packed_shortest_path.front() == phantom_node_pair.startPhantom.reverse_node_id), + (packed_shortest_path.front() == phantom_node_pair.startPhantom.forward_node_id), phantom_node_pair.targetPhantom.fwd_segment_position,//( packed_forward_path.back() == phantom_node_pair.targetPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.targetPhantom.fwd_segment_position, raw_route_data.unpacked_path_segments.front() ); diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 224e53a10..7f1a009c6 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -149,12 +149,6 @@ public: // std::cout << packed_path[i] << " "; // } - bool segment_reversed = false; - - SimpleLogger().Write(logDEBUG) << "fwd offset: " << fwd_index_offset; - SimpleLogger().Write(logDEBUG) << "rev offset: " << rev_index_offset; - SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << ( start_traversed_in_reverse ? "y" : "n" ); - // SimpleLogger().Write() << "starting unpack"; const unsigned packed_path_size = packed_path.size(); std::stack > recursion_stack; @@ -168,6 +162,7 @@ public: std::pair edge; while(!recursion_stack.empty()) { + bool segment_reversed = false; edge = recursion_stack.top(); recursion_stack.pop(); @@ -216,6 +211,13 @@ public: // // SimpleLogger().Write(logDEBUG) << "first geometry: " << id_vector.front() << ", last geometry: " << id_vector.back(); const bool edge_is_reversed = (!ed.forward && ed.backward); + SimpleLogger().Write(logDEBUG) << "fwd offset: " << fwd_index_offset; + SimpleLogger().Write(logDEBUG) << "rev offset: " << rev_index_offset; + SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << ( start_traversed_in_reverse ? "y" : "n" ); + SimpleLogger().Write(logDEBUG) << "edge_is_reversed: " << ( edge_is_reversed ? "y" : "n" ); + + + // if( edge_is_reversed ) { // SimpleLogger().Write(logDEBUG) << "reversing geometry"; @@ -230,8 +232,14 @@ public: BOOST_FOREACH(unsigned number, id_vector) { SimpleLogger().Write() << "[" << number << "] " << facade->GetCoordinateOfNode(number); } - const int start_index = ( ( start_traversed_in_reverse ) ? fwd_index_offset : 0 ); - const int end_index = ( ( start_traversed_in_reverse ) ? id_vector.size() : fwd_index_offset ); + int start_index = ( ( start_traversed_in_reverse ) ? 0 : id_vector.size() - fwd_index_offset ); + int end_index = ( ( start_traversed_in_reverse ) ? id_vector.size() + 1 - fwd_index_offset : id_vector.size() ); + + if( edge_is_reversed ) { + start_index = ( ( !start_traversed_in_reverse ) ? id_vector.size() - fwd_index_offset - 1: fwd_index_offset ); + end_index = ( ( !start_traversed_in_reverse ) ? id_vector.size() : id_vector.size() + 1 - fwd_index_offset ); + } + // BOOST_ASSERT( start_index >= 0 ); // // BOOST_ASSERT( start_index <= end_index ); From 874c579f863fb2c25d1fc579dd0ea0d6f9835ad8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 27 Feb 2014 19:49:53 +0100 Subject: [PATCH 16/89] correctly unpacking the first segment --- Contractor/EdgeBasedGraphFactory.cpp | 211 ++++++--------------- Contractor/GeometryCompressor.cpp | 10 - DataStructures/Coordinate.cpp | 2 +- DataStructures/EdgeBasedNode.h | 35 +++- DataStructures/StaticRTree.h | 10 +- RoutingAlgorithms/AlternativePathRouting.h | 2 +- RoutingAlgorithms/BasicRoutingInterface.h | 154 +++++++-------- 7 files changed, 156 insertions(+), 268 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 40c66a61f..7b716ecf4 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -299,53 +299,29 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( // find forward edge id and // const EdgeID e1 = m_node_based_graph->FindEdge(u, v); - BOOST_ASSERT( e1 != std::numeric_limits::max() ); + BOOST_ASSERT( e1 != SPECIAL_EDGEID ); const EdgeData & forward_data = m_node_based_graph->GetEdgeData(e1); - if( forward_data.edgeBasedNodeID == std::numeric_limits::max() ) { - for(EdgeIterator id = m_node_based_graph->BeginEdges(v); id < m_node_based_graph->EndEdges(v); ++id) { - SimpleLogger().Write(logDEBUG) << " id: " << id << ", edge (" << v << "," << m_node_based_graph->GetTarget(id) << ")"; - } - SimpleLogger().Write() << std::setprecision(6) << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION << " <-> " << - 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; - - if( forward_data.ignore_in_grid ) { - // SimpleLogger().Write(logDEBUG) << "skipped edge at " << m_node_info_list[u].lat << "," << - // m_node_info_list[u].lon << " - " << - // m_node_info_list[v].lat << "," << - // m_node_info_list[v].lon; - return; - } - - BOOST_ASSERT( forward_data.forward ); // find reverse edge id and const EdgeID e2 = m_node_based_graph->FindEdge(v, u); + #ifndef NDEBUG if ( e2 == m_node_based_graph->EndEdges(v) ) { - SimpleLogger().Write(logDEBUG) << "Did not find edge (" << v << "," << u << ")"; + SimpleLogger().Write(logWARNING) << "Did not find edge (" << v << "," << u << ")"; } #endif - BOOST_ASSERT( e2 != std::numeric_limits::max() ); + BOOST_ASSERT( e2 != SPECIAL_EDGEID ); BOOST_ASSERT( e2 < m_node_based_graph->EndEdges(v) ); const EdgeData & reverse_data = m_node_based_graph->GetEdgeData(e2); - // if( forward_data.forward == reverse_data.forward && forward_data.forward != forward_data.backward ) { - // SimpleLogger().Write(logDEBUG) << "flags on edge (" << u << "," << v << "), e1: " << e1 << ", e2: " << e2; - // SimpleLogger().Write(logDEBUG) << "fwd-fwd: " << (forward_data.forward ? "y" : "n"); - // SimpleLogger().Write(logDEBUG) << "fwd-rev: " << (forward_data.backward ? "y": "n"); - // SimpleLogger().Write(logDEBUG) << "rev-fwd: " << (reverse_data.forward ? "y" : "n"); - // SimpleLogger().Write(logDEBUG) << "rev-rev: " << (reverse_data.backward ? "y": "n"); - // SimpleLogger().Write(logDEBUG) << "outgoing edges to "; - // for(EdgeIterator id = m_node_based_graph->BeginEdges(v); id < m_node_based_graph->EndEdges(v); ++id) { - // SimpleLogger().Write(logDEBUG) << " id: " << id << ", edge (" << v << "," << m_node_based_graph->GetTarget(id) << ")"; - // } - // BOOST_ASSERT( reverse_data.edgeBasedNodeID != std::numeric_limits::max() ); - // } else { - // BOOST_ASSERT( reverse_data.edgeBasedNodeID == std::numeric_limits::max() ); - // } + if( + forward_data.edgeBasedNodeID == SPECIAL_NODEID && + reverse_data.edgeBasedNodeID == SPECIAL_NODEID + ) { + return; + } + + BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e1) == m_geometry_compressor.HasEntryForID(e2) ); if( m_geometry_compressor.HasEntryForID(e1) ) { BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e2) ); @@ -356,82 +332,41 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); BOOST_ASSERT( 0 != forward_geometry.size() ); - int fwd_sum_of_weights = 0; - NodeID fwd_start_node = u; - // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - // if( 1 == e1 ) { - // SimpleLogger().Write(logDEBUG) << "fwd edge id: " << e1; + // int fwd_sum_of_weights = 0; + // NodeID fwd_start_node = u; + // BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, forward_geometry) { + // const NodeID fwd_end_node = geometry_node.first; + // const EdgeWeight fwd_weight = geometry_node.second; + // fwd_sum_of_weights += fwd_weight; + // fwd_start_node = fwd_end_node; // } - BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, forward_geometry) { - const NodeID fwd_end_node = geometry_node.first; - const EdgeWeight fwd_weight = geometry_node.second; - // SimpleLogger().Write(logDEBUG) << "fwd node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; - fwd_sum_of_weights += fwd_weight; - // if( 1 == e1 ) { - // SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << fwd_end_node << "), w: " << fwd_weight; - // } - fwd_start_node = fwd_end_node; - } - // if( 1 == e1 ) { - // SimpleLogger().Write(logDEBUG) << "fwd-edge (" << fwd_start_node << "," << v << "), w: " << (forward_data.distance - fwd_sum_of_weights); + // BOOST_ASSERT( forward_data.distance == fwd_sum_of_weights ); + + // int rev_sum_of_weights = 0; + // NodeID rev_start_node = v; + // BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, reverse_geometry) { + // const NodeID rev_end_node = geometry_node.first; + // const EdgeWeight rev_weight = geometry_node.second; + + // rev_sum_of_weights += rev_weight; + // rev_start_node = rev_end_node; // } - // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; - // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[v].lat/COORDINATE_PRECISION << "," << m_node_info_list[v].lon/COORDINATE_PRECISION; - // BOOST_FOREACH(const GeometryCompressor::CompressedNode geometry_node, reverse_geometry) { - // SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION; - // } - // SimpleLogger().Write(logDEBUG) << "rev node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - // if( 1 == e1 ) { - // SimpleLogger().Write(logDEBUG) << "fwd sum of edge weights: " << fwd_sum_of_weights; - // SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << forward_data.distance; - // SimpleLogger().Write(logDEBUG) << "weight diff: " << (forward_data.distance - fwd_sum_of_weights); - // } - BOOST_ASSERT( forward_data.distance == fwd_sum_of_weights ); + // BOOST_ASSERT( reverse_data.distance == rev_sum_of_weights ); - - int rev_sum_of_weights = 0; - NodeID rev_start_node = v; - // SimpleLogger().Write(logDEBUG) << "fwd node " << "weight" << "," << m_node_info_list[u].lat/COORDINATE_PRECISION << "," << m_node_info_list[u].lon/COORDINATE_PRECISION; - BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, reverse_geometry) { - const NodeID rev_end_node = geometry_node.first; - const EdgeWeight rev_weight = geometry_node.second; - - // SimpleLogger().Write(logDEBUG) << "rev node " << geometry_node.first << "," << m_node_info_list[geometry_node.first].lat/COORDINATE_PRECISION << "," << m_node_info_list[geometry_node.first].lon/COORDINATE_PRECISION << ", w: " << geometry_node.second; - rev_sum_of_weights += rev_weight; - // if( 1 == e1 ) { - // SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << rev_end_node << "), w: " << rev_weight; - // } - rev_start_node = rev_end_node; - } - // if( 1 == e1 ) { - // SimpleLogger().Write(logDEBUG) << "Edge (" << rev_start_node << "," << u << "), w: " << (reverse_data.distance - rev_sum_of_weights); - - // SimpleLogger().Write(logDEBUG) << "rev sum of edge weights: " << rev_sum_of_weights; - // SimpleLogger().Write(logDEBUG) << "c'ted edge weight: " << reverse_data.distance; - // SimpleLogger().Write(logDEBUG) << "weight diff: " << (reverse_data.distance - rev_sum_of_weights); - - BOOST_ASSERT( reverse_data.distance == rev_sum_of_weights ); - // // BOOST_ASSERT(false); - // } - // SimpleLogger().Write(logDEBUG) << "start " << m_node_info_list[u].lat << "," << m_node_info_list[u].lon; - // SimpleLogger().Write(logDEBUG) << "target " << m_node_info_list[v].lat << "," << m_node_info_list[v].lon; - // BOOST_ASSERT( false ); - - //TODO reconstruct bidirectional edge with individual weights and put each into the NN index + // reconstruct bidirectional edge with individual weights and put each into the NN index std::vector forward_dist_prefix_sum( forward_geometry.size() ); std::vector reverse_dist_prefix_sum( reverse_geometry.size() ); - //quick'n'dirty prefix sum as std::partial_sum needs addtional casts + // quick'n'dirty prefix sum as std::partial_sum needs addtional casts // SimpleLogger().Write(logDEBUG) << "Prefix sums of edge " << e1 << ", w: " << reverse_data.distance; int temp_sum = 0; for( unsigned i = 0; i < forward_geometry.size(); ++i ) { temp_sum += forward_geometry[i].second; BOOST_ASSERT( forward_data.distance >= temp_sum ); forward_dist_prefix_sum[i] = forward_data.distance - temp_sum; - // SimpleLogger().Write(logDEBUG) << "[" << i << "]" << temp_sum << ", n: " << forward_geometry[i].first << ", loc: " << m_node_info_list[forward_geometry[i].first].lat/COORDINATE_PRECISION << "," << m_node_info_list[forward_geometry[i].first].lon/COORDINATE_PRECISION; } BOOST_ASSERT( forward_data.distance == temp_sum ); temp_sum = 0; @@ -439,7 +374,6 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( temp_sum += reverse_geometry[i].second; BOOST_ASSERT( reverse_data.distance >= temp_sum ); reverse_dist_prefix_sum[i] = reverse_data.distance - temp_sum; - // SimpleLogger().Write(logDEBUG) << "[" << i << "]" << temp_sum << ", n: " << reverse_geometry[i].first << ", loc: " << m_node_info_list[reverse_geometry[i].first].lat/COORDINATE_PRECISION << "," << m_node_info_list[reverse_geometry[i].first].lon/COORDINATE_PRECISION; } BOOST_ASSERT( reverse_data.distance == temp_sum ); @@ -453,11 +387,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( current_edge_start_coordinate_id == reverse_geometry[geometry_size-1-i].first ); const NodeID current_edge_target_coordinate_id = forward_geometry[i].first; - // SimpleLogger().Write() << "adding edge (" << current_edge_start_coordinate_id << "," << forward_geometry[i].first << ") "; - // SimpleLogger().Write() << "fwd w: " << forward_geometry[i].second << ", fwd o: " << forward_dist_prefix_sum[i]; - // SimpleLogger().Write() << "rev w: " << reverse_geometry[geometry_size-1-i].second << ", rev o: " << reverse_dist_prefix_sum[geometry_size-1-i]; - - //TODO: build edges + // build edges m_edge_based_node_list.push_back( EdgeBasedNode( forward_data.edgeBasedNodeID, @@ -471,7 +401,8 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( reverse_dist_prefix_sum[geometry_size-1-i], i, geometry_size-1-i, - belongs_to_tiny_cc + belongs_to_tiny_cc, + true ) ); current_edge_start_coordinate_id = current_edge_target_coordinate_id; @@ -511,6 +442,11 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( // BOOST_ASSERT( forward_data.forward == reverse_data.backward ); // BOOST_ASSERT( reverse_data.forward == forward_data.backward ); + BOOST_ASSERT( + forward_data.edgeBasedNodeID != SPECIAL_NODEID || + reverse_data.edgeBasedNodeID != SPECIAL_NODEID + ); + //TODO: emplace_back with C++11 m_edge_based_node_list.push_back( EdgeBasedNode( @@ -525,7 +461,8 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( 0, 0, 0, - belongs_to_tiny_cc + belongs_to_tiny_cc, + false ) ); BOOST_ASSERT( !m_edge_based_node_list.back().IsCompressed() ); @@ -641,8 +578,6 @@ void EdgeBasedGraphFactory::Run( FixupStartingTurnRestriction( w, v, u ); FixupArrivingTurnRestriction( w, v, u ); - // const int reverse_weight2 = rev_edge_data2.distance; - // store compressed geometry in container m_geometry_compressor.CompressEdge( forward_e1, @@ -686,7 +621,6 @@ void EdgeBasedGraphFactory::Run( for(EdgeIterator current_edge = m_node_based_graph->BeginEdges(current_node); current_edge < m_node_based_graph->EndEdges(current_node); ++current_edge) { EdgeData & edge_data = m_node_based_graph->GetEdgeData(current_edge); if( !edge_data.forward ) { - // SimpleLogger().Write(logDEBUG) << "skipped edge (" << source << "," << target << ")=[" << current_edge_id << "]"; continue; } @@ -722,8 +656,7 @@ void EdgeBasedGraphFactory::Run( SimpleLogger().Write() << "identified: " << component_index_size.size() << " many components"; - SimpleLogger().Write() << - "generating edge-expanded nodes"; + SimpleLogger().Write() << "generating edge-expanded nodes"; p.reinit(m_node_based_graph->GetNumberOfNodes()); @@ -737,22 +670,24 @@ void EdgeBasedGraphFactory::Run( BOOST_ASSERT( u < m_node_based_graph->GetNumberOfNodes() ); p.printIncrement(); for( - EdgeIterator e1 = m_node_based_graph->BeginEdges(u), + EdgeID e1 = m_node_based_graph->BeginEdges(u), last_edge = m_node_based_graph->EndEdges(u); e1 < last_edge; ++e1 ) { const EdgeData & edge_data = m_node_based_graph->GetEdgeData(e1); - if( edge_data.edgeBasedNodeID == std::numeric_limits::max() ) { - continue; + if( edge_data.edgeBasedNodeID == SPECIAL_NODEID ) { + // continue; } - BOOST_ASSERT( e1 != std::numeric_limits::max() ); - NodeIterator v = m_node_based_graph->GetTarget(e1); - BOOST_ASSERT( std::numeric_limits::max() != v ); + BOOST_ASSERT( e1 != SPECIAL_EDGEID ); + const NodeID v = m_node_based_graph->GetTarget(e1); + + BOOST_ASSERT( SPECIAL_NODEID != v ); // pick only every other edge if( u > v ) { continue; } + // BOOST_ASSERT( u < v ); BOOST_ASSERT( edge_data.type != SHRT_MAX ); @@ -764,40 +699,10 @@ void EdgeBasedGraphFactory::Run( ); const bool component_is_tiny = ( size_of_component < 1000 ); - InsertEdgeBasedNode( u, v, e1, component_is_tiny ); } } - // for( - // NodeIterator u = 0, end = m_node_based_graph->GetNumberOfNodes(); - // u < end; - // ++u - // ) { - // BOOST_ASSERT( u != std::numeric_limits::max() ); - // BOOST_ASSERT( u < m_node_based_graph->GetNumberOfNodes() ); - // p.printIncrement(); - // for( - // EdgeIterator e1 = m_node_based_graph->BeginEdges(u), - // last_edge = m_node_based_graph->EndEdges(u); - // e1 < last_edge; - // ++e1 - // ) { - // BOOST_ASSERT( e1 != std::numeric_limits::max() ); - // NodeIterator v = m_node_based_graph->GetTarget(e1); - - // EdgeIterator e2 = m_node_based_graph->FindEdge(u, v); - // BOOST_ASSERT( e2 != m_node_based_graph->EndEdges(v) ); - // BOOST_ASSERT( e1 == e2 ); - - // const EdgeData & data = m_node_based_graph->GetEdgeData(e1); - // if( data.forward ) { - // BOOST_ASSERT( data.edgeBasedNodeID != std::numeric_limits::max() ); - // } - - // } - // } - m_number_of_edge_based_nodes = numbered_edges_count; SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << @@ -855,8 +760,9 @@ void EdgeBasedGraphFactory::Run( continue; } const NodeIterator w = m_node_based_graph->GetTarget(e2); + if( - to_node_of_only_restriction != std::numeric_limits::max() && + to_node_of_only_restriction != SPECIAL_NODEID && w != to_node_of_only_restriction ) { //We are at an only_-restriction but not at the right turn. @@ -880,7 +786,7 @@ void EdgeBasedGraphFactory::Run( //at the end of a dead-end street if ( CheckIfTurnIsRestricted(u, v, w) && - (to_node_of_only_restriction == std::numeric_limits::max()) && + (to_node_of_only_restriction == SPECIAL_NODEID) && (w != to_node_of_only_restriction) ) { ++restricted_turns_counter; @@ -916,12 +822,9 @@ void EdgeBasedGraphFactory::Run( distance += turn_penalty; const bool edge_is_compressed = m_geometry_compressor.HasEntryForID(e1); + if(edge_is_compressed) { ++compressed; - // m_geometry_compressor.AddLastViaNodeIDToCompressedEdge(e1, v, /*TODO*/ 1); - if ( 0 == m_geometry_compressor.GetPositionForID(e1) ) { - SimpleLogger().Write(logDEBUG) << "e1: " << e1 << " is zero with via node: " << v; - } } original_edge_data_vector.push_back( @@ -932,6 +835,7 @@ void EdgeBasedGraphFactory::Run( edge_is_compressed ) ); + ++original_edges_counter; if(original_edge_data_vector.size() > 100000) { @@ -941,6 +845,9 @@ void EdgeBasedGraphFactory::Run( ); } + BOOST_ASSERT( SPECIAL_NODEID != edge_data1.edgeBasedNodeID ); + BOOST_ASSERT( SPECIAL_NODEID != edge_data2.edgeBasedNodeID ); + m_edge_based_edge_list.push_back( EdgeBasedEdge( edge_data1.edgeBasedNodeID, diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index e5974b602..522250a2d 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -166,10 +166,6 @@ void GeometryCompressor::CompressEdge( std::vector & edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1]; - if( 0 == edge_id_1 ) { - SimpleLogger().Write(logDEBUG) << "adding via " << via_node_id << ", w: " << weight1; - } - if( edge_bucket_list1.empty() ) { edge_bucket_list1.push_back( std::make_pair(via_node_id, weight1) ); } @@ -183,12 +179,6 @@ void GeometryCompressor::CompressEdge( BOOST_ASSERT( list_to_remove_index < m_compressed_geometries.size() ); std::vector & edge_bucket_list2 = m_compressed_geometries[list_to_remove_index]; - if( 0 == edge_id_1 ) { - SimpleLogger().Write(logDEBUG) << "appending to list: "; - BOOST_FOREACH(const CompressedNode & node, edge_bucket_list2) { - SimpleLogger().Write(logDEBUG) << "adding via " << node.first << ", w: " << node.second; - } - } // found an existing list, append it to the list of edge_id_1 edge_bucket_list1.insert( diff --git a/DataStructures/Coordinate.cpp b/DataStructures/Coordinate.cpp index 90e44eac0..e34dc7f32 100644 --- a/DataStructures/Coordinate.cpp +++ b/DataStructures/Coordinate.cpp @@ -174,5 +174,5 @@ void FixedPointCoordinate::convertInternalReversedCoordinateToString( } void FixedPointCoordinate::Output(std::ostream & out) const {//, FixedPointCoordinate & c) { - out << "(" << lat << "," << lon << ")"; + out << "(" << lat/COORDINATE_PRECISION << "," << lon/COORDINATE_PRECISION << ")"; } diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index fba3f39f5..845d1a184 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -23,11 +23,12 @@ struct EdgeBasedNode { forward_offset(0), reverse_offset(0), fwd_segment_position( std::numeric_limits::max() ), - rev_segment_position( std::numeric_limits::max() >> 1 ), - belongsToTinyComponent(false) + rev_segment_position( std::numeric_limits::max() >> 2 ), + belongsToTinyComponent(false), + is_compressed(false) { } - EdgeBasedNode( + explicit EdgeBasedNode( NodeID forward_edge_based_node_id, NodeID reverse_edge_based_node_id, NodeID u, @@ -39,7 +40,8 @@ struct EdgeBasedNode { int reverse_offset, unsigned short fwd_segment_position, unsigned short rev_segment_position, - bool belongsToTinyComponent + bool belongsToTinyComponent, + bool is_compressed ) : forward_edge_based_node_id(forward_edge_based_node_id), reverse_edge_based_node_id(reverse_edge_based_node_id), @@ -52,10 +54,23 @@ struct EdgeBasedNode { reverse_offset(reverse_offset), fwd_segment_position(fwd_segment_position), rev_segment_position(rev_segment_position), - belongsToTinyComponent(belongsToTinyComponent) - { } - // Computes: - // - the distance from the given query location to nearest point on this edge (and returns it) + belongsToTinyComponent(belongsToTinyComponent), + is_compressed(is_compressed) + { + BOOST_ASSERT( + ( forward_edge_based_node_id != SPECIAL_NODEID ) || + ( reverse_edge_based_node_id != SPECIAL_NODEID ) + ); + // if( forward_edge_based_node_id == SPECIAL_NODEID ) { + // using namespace std; + // swap( forward_edge_based_node_id, reverse_edge_based_node_id ); + // swap( u, v ); + // swap( forward_weight, reverse_weight ); + // swap( forward_offset, reverse_offset ); + // swap( fwd_segment_position, rev_segment_position ); + // } + } + inline static double ComputePerpendicularDistance( const FixedPointCoordinate & coord_a, const FixedPointCoordinate & coord_b, @@ -134,7 +149,7 @@ struct EdgeBasedNode { } bool IsCompressed() { - return (fwd_segment_position + rev_segment_position) != 0; + return is_compressed; } // Returns the midpoint of the underlying edge. @@ -152,7 +167,7 @@ struct EdgeBasedNode { int forward_offset; int reverse_offset; unsigned short fwd_segment_position; - unsigned short rev_segment_position:15; + unsigned short rev_segment_position:14; //TODO: not actually needed! bool belongsToTinyComponent:1; NodeID name_id; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 9e62cd663..e96848ef1 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -683,11 +683,11 @@ public: BOOST_ASSERT( 0. <= current_perpendicular_distance ); if( - ( current_perpendicular_distance < min_dist ) //&& - // !DoubleEpsilonCompare( - // current_perpendicular_distance, - // min_dist - // ) + ( current_perpendicular_distance < min_dist ) && + !DoubleEpsilonCompare( + current_perpendicular_distance, + min_dist + ) ) { //found a new minimum min_dist = current_perpendicular_distance; result_phantom_node.forward_node_id = current_edge.forward_edge_based_node_id; diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index b9d7943d1..530ab2188 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -294,7 +294,7 @@ public: super::UnpackPath( packed_shortest_path, phantom_node_pair.startPhantom.fwd_segment_position, - (packed_shortest_path.front() == phantom_node_pair.startPhantom.forward_node_id), + (packed_shortest_path.front() != phantom_node_pair.startPhantom.forward_node_id), phantom_node_pair.targetPhantom.fwd_segment_position,//( packed_forward_path.back() == phantom_node_pair.targetPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.targetPhantom.fwd_segment_position, raw_route_data.unpacked_path_segments.front() ); diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 7f1a009c6..2d8415e1d 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -69,7 +69,7 @@ public: ) const { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); - //SimpleLogger().Write() << "Settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; + SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " 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 ){ @@ -143,13 +143,6 @@ public: int rev_index_offset, std::vector & unpacked_path ) const { - - // SimpleLogger().Write(logDEBUG) << "unpacking path"; - // for(unsigned i = 0; i < packed_path.size(); ++i) { - // std::cout << packed_path[i] << " "; - // } - - // SimpleLogger().Write() << "starting unpack"; const unsigned packed_path_size = packed_path.size(); std::stack > recursion_stack; @@ -162,17 +155,50 @@ public: std::pair edge; while(!recursion_stack.empty()) { - bool segment_reversed = false; + // bool segment_reversed = false; edge = recursion_stack.top(); recursion_stack.pop(); - EdgeID smaller_edge_id = facade->FindEdgeIndicateIfReverse( - edge.first, - edge.second, - segment_reversed - ); + // facade->FindEdge does not suffice here in case of shortcuts. + // The above explanation unclear? Think! + EdgeID smaller_edge_id = SPECIAL_EDGEID; + int edge_weight = INT_MAX; + 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(edge_id) == edge.second) && + (weight < edge_weight) && + facade->GetEdgeData(edge_id).forward + ){ + smaller_edge_id = edge_id; + edge_weight = weight; + } + } + if( SPECIAL_EDGEID == smaller_edge_id ){ + 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(edge_id) == edge.first) && + (weight < edge_weight) && + facade->GetEdgeData(edge_id).backward + ){ + smaller_edge_id = edge_id; + edge_weight = weight; + } + } + } + BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); - BOOST_ASSERT( SPECIAL_EDGEID != smaller_edge_id ); + + BOOST_ASSERT( facade->EndEdges(edge.first) != smaller_edge_id ); const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if( ed.shortcut ) {//unpack @@ -185,7 +211,6 @@ public: unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id); const TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); - //TODO: refactor to iterate over a result vector in both cases if ( !facade->EdgeIsCompressed(ed.id) ){ BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) ); unpacked_path.push_back( @@ -200,81 +225,27 @@ public: std::vector id_vector; facade->GetUncompressedGeometry(ed.id, id_vector); + const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - fwd_index_offset - 1 : fwd_index_offset ) : 0 ); + const int end_index = id_vector.size(); - //TODO use only a single for loop - if( unpacked_path.empty() ) { - // // SimpleLogger().Write(logDEBUG) << "1st node in packed path: " << packed_path.front() << ", edge (" << edge.first << "," << edge.second << ")"; - // // SimpleLogger().Write(logDEBUG) << "REVERSED1: " << ( facade->GetTarget(smaller_edge_id) != edge.second ? "y" : "n" ); - // // SimpleLogger().Write(logDEBUG) << "REVERSED2: " << ( facade->GetTarget(smaller_edge_id) != edge.first ? "y" : "n" ); - // SimpleLogger().Write(logDEBUG) << "segment_reversed: " << ( segment_reversed ? "y" : "n" ); - // // SimpleLogger().Write(logDEBUG) << "target of edge: " << facade->GetTarget(smaller_edge_id); - // // SimpleLogger().Write(logDEBUG) << "first geometry: " << id_vector.front() << ", last geometry: " << id_vector.back(); - - const bool edge_is_reversed = (!ed.forward && ed.backward); - SimpleLogger().Write(logDEBUG) << "fwd offset: " << fwd_index_offset; - SimpleLogger().Write(logDEBUG) << "rev offset: " << rev_index_offset; - SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << ( start_traversed_in_reverse ? "y" : "n" ); - SimpleLogger().Write(logDEBUG) << "edge_is_reversed: " << ( edge_is_reversed ? "y" : "n" ); - - - - - // if( edge_is_reversed ) { - // SimpleLogger().Write(logDEBUG) << "reversing geometry"; - // std::reverse( id_vector.begin(), id_vector.end() ); - // fwd_index_offset = id_vector.size() - (1+fwd_index_offset); - // SimpleLogger().Write() << "new fwd offset: " << fwd_index_offset; - // } - - SimpleLogger().Write(logDEBUG) << "edge data fwd: " << (ed.forward ? "y": "n") << ", reverse: " << (ed.backward ? "y" : "n" ); - SimpleLogger().Write() << "Edge " << ed.id << "=(" << edge.first << "," << edge.second << ") is compressed"; - SimpleLogger().Write(logDEBUG) << "packed ids: "; - BOOST_FOREACH(unsigned number, id_vector) { - SimpleLogger().Write() << "[" << number << "] " << facade->GetCoordinateOfNode(number); - } - int start_index = ( ( start_traversed_in_reverse ) ? 0 : id_vector.size() - fwd_index_offset ); - int end_index = ( ( start_traversed_in_reverse ) ? id_vector.size() + 1 - fwd_index_offset : id_vector.size() ); - - if( edge_is_reversed ) { - start_index = ( ( !start_traversed_in_reverse ) ? id_vector.size() - fwd_index_offset - 1: fwd_index_offset ); - end_index = ( ( !start_traversed_in_reverse ) ? id_vector.size() : id_vector.size() + 1 - fwd_index_offset ); - } - - - // BOOST_ASSERT( start_index >= 0 ); - // // BOOST_ASSERT( start_index <= end_index ); - SimpleLogger().Write(logDEBUG) << "geometry count: " << id_vector.size() << ", fetching[" << start_index << "..." << end_index << "]"; - for( - unsigned i = start_index; - i != end_index; - (start_index > end_index) ? --i : ++i - ) { - SimpleLogger().Write(logDEBUG) << "[" << i << "]pushing id: " << id_vector[i]; - unpacked_path.push_back( - PathData( - id_vector[i], - name_index, - TurnInstructionsClass::NoTurn, - 0 - ) - ); - } - } else { - BOOST_FOREACH(const unsigned coordinate_id, id_vector){ - // SimpleLogger().Write(logDEBUG) << "pushing id: " << coordinate_id; - unpacked_path.push_back( - PathData( - coordinate_id, - name_index, - TurnInstructionsClass::NoTurn, - 0 - ) - ); - - } - unpacked_path.back().turnInstruction = turn_instruction; - unpacked_path.back().durationOfSegment = ed.distance; + BOOST_ASSERT( start_index >= 0 ); + BOOST_ASSERT( start_index <= end_index ); + for( + unsigned i = start_index; + i < end_index; + ++i + ) { + unpacked_path.push_back( + PathData( + id_vector[i], + name_index, + TurnInstructionsClass::NoTurn, + 0 + ) + ); } + unpacked_path.back().turnInstruction = turn_instruction; + unpacked_path.back().durationOfSegment = ed.distance; } } } @@ -368,6 +339,11 @@ public: current_node_id = reverse_heap.GetData(current_node_id).parent; packed_path.push_back(current_node_id); } + + + BOOST_FOREACH(NodeID node, packed_path) { + SimpleLogger().Write(logDEBUG) << "node: " << node; + } } //TODO: reorder parameters From eca09e6c812539e24f058098ffb015b575917100 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 28 Feb 2014 17:14:38 +0100 Subject: [PATCH 17/89] unpacking of target segment works --- Contractor/EdgeBasedGraphFactory.cpp | 34 ++++++++--------- Contractor/GeometryCompressor.cpp | 2 +- DataStructures/EdgeBasedNode.h | 31 +++++---------- DataStructures/PhantomNodes.h | 6 +-- DataStructures/StaticRTree.h | 7 +++- RoutingAlgorithms/AlternativePathRouting.h | 8 ++-- RoutingAlgorithms/BasicRoutingInterface.h | 44 ++++++++++++++++++---- RoutingAlgorithms/ShortestPathRouting.h | 2 +- Server/DataStructures/InternalDataFacade.h | 4 +- 9 files changed, 80 insertions(+), 58 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 7b716ecf4..40a7c2803 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -128,13 +128,6 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( edge.data.SwapDirectionFlags(); edges_list.push_back( edge ); } - - // if( import_edge.source() == 150903 || import_edge.target() == 150903 ) { - // SimpleLogger().Write(logDEBUG) << "[" << edges_list.size() << "] (" << import_edge.source() << "," << import_edge.target() << "), w: " << import_edge.weight(); - // if( import_edge.IsSplit() ) { - // SimpleLogger().Write(logDEBUG) << "edge split: (" << import_edge.source() << "," << import_edge.target() << ")"; - // } - // } } std::vector().swap(input_edge_list); @@ -297,7 +290,8 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( e1 != SPECIAL_EDGEID ); // find forward edge id and - // const EdgeID e1 = m_node_based_graph->FindEdge(u, v); + const EdgeID e1b = m_node_based_graph->FindEdge(u, v); + BOOST_ASSERT( e1 == e1b ); BOOST_ASSERT( e1 != SPECIAL_EDGEID ); const EdgeData & forward_data = m_node_based_graph->GetEdgeData(e1); @@ -322,8 +316,16 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( } BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e1) == m_geometry_compressor.HasEntryForID(e2) ); - if( m_geometry_compressor.HasEntryForID(e1) ) { + if(forward_data.edgeBasedNodeID == 16176) { + SimpleLogger().Write(logDEBUG) << "reverse_data.edgeBasedNodeID=" << reverse_data.edgeBasedNodeID; + SimpleLogger().Write(logDEBUG) << "u: " << u << ", v: " << v << " at " << m_node_info_list.at(u).lat/COORDINATE_PRECISION << "," + << m_node_info_list.at(u).lon/COORDINATE_PRECISION << "<->" << m_node_info_list.at(v).lat/COORDINATE_PRECISION << "," + << m_node_info_list.at(v).lon/COORDINATE_PRECISION; + SimpleLogger().Write(logDEBUG) << "pos(" << e1 << ")=" << m_geometry_compressor.GetPositionForID(e1); + SimpleLogger().Write(logDEBUG) << "pos(" << e2 << ")=" << m_geometry_compressor.GetPositionForID(e2); + } + BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e2) ); // reconstruct geometry and put in each individual edge with its offset @@ -399,10 +401,9 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( reverse_geometry[geometry_size-1-i].second, forward_dist_prefix_sum[i], reverse_dist_prefix_sum[geometry_size-1-i], + m_geometry_compressor.GetPositionForID(e1), i, - geometry_size-1-i, - belongs_to_tiny_cc, - true + belongs_to_tiny_cc ) ); current_edge_start_coordinate_id = current_edge_target_coordinate_id; @@ -419,7 +420,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( v != m_edge_based_node_list.back().u ); } - //TODO: Manually reconstruct last edge. + BOOST_ASSERT( current_edge_start_coordinate_id == v ); BOOST_ASSERT( m_edge_based_node_list.back().IsCompressed() ); @@ -459,10 +460,9 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( reverse_data.distance, 0, 0, + SPECIAL_EDGEID, 0, - 0, - belongs_to_tiny_cc, - false + belongs_to_tiny_cc ) ); BOOST_ASSERT( !m_edge_based_node_list.back().IsCompressed() ); @@ -688,7 +688,7 @@ void EdgeBasedGraphFactory::Run( 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/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 522250a2d..b9cb1739a 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -64,7 +64,6 @@ unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const { void GeometryCompressor::SerializeInternalVector( const std::string & path ) const { - //TODO: remove super-trivial geometries std::ofstream geometry_out_stream( path.c_str(), std::ios::binary ); const unsigned number_of_compressed_geometries = m_compressed_geometries.size()+1; @@ -129,6 +128,7 @@ void GeometryCompressor::CompressEdge( const EdgeWeight weight1, const EdgeWeight weight2 ) { + //TODO: remove super-trivial geometries BOOST_ASSERT( SPECIAL_EDGEID != edge_id_1 ); BOOST_ASSERT( SPECIAL_EDGEID != edge_id_2 ); diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index 845d1a184..7a314369b 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -18,14 +18,13 @@ struct EdgeBasedNode { u(SPECIAL_NODEID), v(SPECIAL_NODEID), name_id(0), - forward_weight(std::numeric_limits::max() >> 1), - reverse_weight(std::numeric_limits::max() >> 1), + forward_weight(INVALID_EDGE_WEIGHT >> 1), + reverse_weight(INVALID_EDGE_WEIGHT >> 1), forward_offset(0), reverse_offset(0), + packed_geometry_id(SPECIAL_EDGEID), fwd_segment_position( std::numeric_limits::max() ), - rev_segment_position( std::numeric_limits::max() >> 2 ), - belongsToTinyComponent(false), - is_compressed(false) + belongsToTinyComponent(false) { } explicit EdgeBasedNode( @@ -38,10 +37,9 @@ struct EdgeBasedNode { int reverse_weight, int forward_offset, int reverse_offset, + unsigned packed_geometry_id, unsigned short fwd_segment_position, - unsigned short rev_segment_position, - bool belongsToTinyComponent, - bool is_compressed + bool belongs_to_tiny_component ) : forward_edge_based_node_id(forward_edge_based_node_id), reverse_edge_based_node_id(reverse_edge_based_node_id), @@ -52,23 +50,14 @@ struct EdgeBasedNode { reverse_weight(reverse_weight), forward_offset(forward_offset), reverse_offset(reverse_offset), + packed_geometry_id(packed_geometry_id), fwd_segment_position(fwd_segment_position), - rev_segment_position(rev_segment_position), - belongsToTinyComponent(belongsToTinyComponent), - is_compressed(is_compressed) + belongsToTinyComponent(belongs_to_tiny_component) { BOOST_ASSERT( ( forward_edge_based_node_id != SPECIAL_NODEID ) || ( reverse_edge_based_node_id != SPECIAL_NODEID ) ); - // if( forward_edge_based_node_id == SPECIAL_NODEID ) { - // using namespace std; - // swap( forward_edge_based_node_id, reverse_edge_based_node_id ); - // swap( u, v ); - // swap( forward_weight, reverse_weight ); - // swap( forward_offset, reverse_offset ); - // swap( fwd_segment_position, rev_segment_position ); - // } } inline static double ComputePerpendicularDistance( @@ -149,7 +138,7 @@ struct EdgeBasedNode { } bool IsCompressed() { - return is_compressed; + return packed_geometry_id != SPECIAL_EDGEID; } // Returns the midpoint of the underlying edge. @@ -158,7 +147,7 @@ struct EdgeBasedNode { } NodeID forward_edge_based_node_id; - NodeID reverse_edge_based_node_id; + NodeID reverse_edge_based_node_id; // needed for edge-expanded graph NodeID u; NodeID v; unsigned name_id; diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 9ce918750..8aa1343d8 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -40,9 +40,9 @@ struct PhantomNode { reverse_weight(INVALID_EDGE_WEIGHT), forward_offset(0), reverse_offset(0), + packed_geometry_id(SPECIAL_EDGEID), ratio(0.), - fwd_segment_position(0), - rev_segment_position(0) + fwd_segment_position(0) { } NodeID forward_node_id; @@ -52,10 +52,10 @@ struct PhantomNode { int reverse_weight; int forward_offset; int reverse_offset; + unsigned packed_geometry_id; double ratio; FixedPointCoordinate location; unsigned short fwd_segment_position; - unsigned short rev_segment_position; int GetForwardWeightPlusOffset() const { diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index e96848ef1..fbd96b23f 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -690,15 +690,17 @@ public: ) ) { //found a new minimum min_dist = current_perpendicular_distance; + //TODO: use assignment c'tor in PhantomNode result_phantom_node.forward_node_id = current_edge.forward_edge_based_node_id; result_phantom_node.reverse_node_id = current_edge.reverse_edge_based_node_id; + 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.packed_geometry_id = current_edge.packed_geometry_id; result_phantom_node.fwd_segment_position = current_edge.fwd_segment_position; - result_phantom_node.rev_segment_position = current_edge.rev_segment_position; - result_phantom_node.name_id = current_edge.name_id; + result_phantom_node.location = nearest; current_start_coordinate.lat = m_coordinate_list->at(current_edge.u).lat; current_start_coordinate.lon = m_coordinate_list->at(current_edge.u).lon; @@ -767,6 +769,7 @@ public: SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight << ", ratio: " << result_phantom_node.ratio; SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id; + SimpleLogger().Write(logDEBUG) << "geom id: " << result_phantom_node.packed_geometry_id; return found_a_nearest_edge; } diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 530ab2188..4ea337f2a 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -288,14 +288,16 @@ public: SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.forward_node_id: " << phantom_node_pair.startPhantom.forward_node_id; SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.reverse_node_id: " << phantom_node_pair.startPhantom.reverse_node_id; - SimpleLogger().Write(logDEBUG) << "packed_shortest_path.front(): " << packed_shortest_path.front(); + SimpleLogger().Write(logDEBUG) << "phantom_node_pair.targetPhantom.packed_geometry_id: " << phantom_node_pair.targetPhantom.packed_geometry_id; // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); super::UnpackPath( packed_shortest_path, phantom_node_pair.startPhantom.fwd_segment_position, (packed_shortest_path.front() != phantom_node_pair.startPhantom.forward_node_id), - phantom_node_pair.targetPhantom.fwd_segment_position,//( packed_forward_path.back() == phantom_node_pair.targetPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.targetPhantom.fwd_segment_position, + phantom_node_pair.targetPhantom.packed_geometry_id, + phantom_node_pair.targetPhantom.fwd_segment_position, + (packed_shortest_path.back() != phantom_node_pair.targetPhantom.forward_node_id), raw_route_data.unpacked_path_segments.front() ); raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; @@ -359,7 +361,7 @@ private: // unpack, supply correct offsets to packed start and end nodes. super::UnpackPath( packed_s_v_path, - 0, false, 0, //TODO: replace by real offsets + 0, false, SPECIAL_EDGEID, 0, false, //TODO: replace by real offsets unpacked_path ); } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 2d8415e1d..6e423f19f 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -69,7 +69,7 @@ public: ) const { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); - SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; + // SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " 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 ){ @@ -136,11 +136,15 @@ public: } } + + //TODO: refactor parameters to only edge ids for start and end inline void UnpackPath( const std::vector & packed_path, - int fwd_index_offset, - bool start_traversed_in_reverse, - int rev_index_offset, + const int fwd_index_offset, + const bool start_traversed_in_reverse, + const unsigned packed_geometry_id_of_last_edge, + const int rev_index_offset, + const bool target_traversed_in_reverse, std::vector & unpacked_path ) const { const unsigned packed_path_size = packed_path.size(); @@ -223,7 +227,7 @@ public: ); } else { std::vector id_vector; - facade->GetUncompressedGeometry(ed.id, id_vector); + facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id), id_vector); const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - fwd_index_offset - 1 : fwd_index_offset ) : 0 ); const int end_index = id_vector.size(); @@ -249,6 +253,31 @@ public: } } } + if(SPECIAL_EDGEID != packed_geometry_id_of_last_edge) { + SimpleLogger().Write(logDEBUG) << "unpacking last segment " << packed_geometry_id_of_last_edge; + std::vector id_vector; + facade->GetUncompressedGeometry(packed_geometry_id_of_last_edge, id_vector); + const int start_index = 0; + const int end_index = rev_index_offset; + + BOOST_ASSERT( start_index >= 0 ); + BOOST_ASSERT( start_index <= end_index ); + for( + unsigned i = start_index; + i < end_index; + ++i + ) { + SimpleLogger().Write(logDEBUG) << facade->GetCoordinateOfNode(id_vector[i]); + unpacked_path.push_back( + PathData( + id_vector[i], + 0, + TurnInstructionsClass::NoTurn, + 0 + ) + ); + } + } } inline void UnpackEdge( @@ -330,8 +359,7 @@ public: current_node_id = forward_heap.GetData(current_node_id).parent; packed_path.push_back(current_node_id); } - //throw away first segment, unpack individually - + SimpleLogger().Write() << "parent of last node. " << forward_heap.GetData(current_node_id).parent; std::reverse(packed_path.begin(), packed_path.end()); packed_path.push_back(middle_node_id); current_node_id = middle_node_id; @@ -340,7 +368,7 @@ public: packed_path.push_back(current_node_id); } - + SimpleLogger().Write(logDEBUG) << "packed path"; BOOST_FOREACH(NodeID node, packed_path) { SimpleLogger().Write(logDEBUG) << "node: " << node; } diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index a711c91a0..bab359ddd 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -365,8 +365,8 @@ public: super::UnpackPath( packed_legs1[i], ( at_beginning ? start_offset : 0), - 0, false, + SPECIAL_EDGEID, 0, false, raw_route_data.unpacked_path_segments[i] ); } diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 5ff639df5..7e0177c68 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -478,9 +478,9 @@ public: } virtual void GetUncompressedGeometry( - const unsigned id, std::vector & result_nodes + const unsigned node, std::vector & result_nodes ) const { - const NodeID node = m_via_node_list.at(id); + // const NodeID node = m_via_node_list.at(id); // SimpleLogger().Write() << "translated " << id << " to " << node; // SimpleLogger().Write() << "getting geometry from compression bucket " << node << "/" << m_compressed_geometry_indices.size(); unsigned begin = m_compressed_geometry_indices.at(node); From 6b91d6692f426e0bda5764521c355e91d9655f22 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 3 Mar 2014 18:47:34 +0100 Subject: [PATCH 18/89] unpacking target correctly, also partial unpacking origin and destination are on the very same packed edge --- DataStructures/PhantomNodes.h | 38 +++++++++++++++------- RoutingAlgorithms/AlternativePathRouting.h | 8 ++++- RoutingAlgorithms/BasicRoutingInterface.h | 13 ++++++-- RoutingAlgorithms/ShortestPathRouting.h | 3 +- Server/RequestHandler.cpp | 4 ++- Server/RequestHandler.h | 9 ++--- 6 files changed, 54 insertions(+), 21 deletions(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 8aa1343d8..bb8630462 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -63,7 +63,7 @@ struct PhantomNode { } int GetReverseWeightPlusOffset() const { - return reverse_weight + reverse_offset; + return reverse_weight - reverse_offset; } void Reset() { @@ -89,8 +89,14 @@ struct PhantomNode { bool isValid(const unsigned numberOfNodes) const { return location.isValid() && - ( (forward_node_id < numberOfNodes) || (reverse_node_id < numberOfNodes) ) && - ( (forward_weight != INVALID_EDGE_WEIGHT) || (reverse_weight != INVALID_EDGE_WEIGHT) ) && + ( + (forward_node_id < numberOfNodes) || + (reverse_node_id < numberOfNodes) + ) && + ( + (forward_weight != INVALID_EDGE_WEIGHT) || + (reverse_weight != INVALID_EDGE_WEIGHT) + ) && (ratio >= 0.) && (ratio <= 1.) && (name_id != std::numeric_limits::max()); @@ -102,6 +108,7 @@ struct PhantomNode { }; struct PhantomNodes { + //TODO: rename to lower-case non-camel PhantomNode startPhantom; PhantomNode targetPhantom; void Reset() { @@ -113,7 +120,6 @@ struct PhantomNodes { return (startPhantom.forward_node_id == targetPhantom.forward_node_id); } - //TODO: Rename to: BothPhantomNodesAreInvalid bool AtLeastOnePhantomNodeIsUINTMAX() const { return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.forward_node_id == SPECIAL_NODEID); @@ -124,16 +130,26 @@ struct PhantomNodes { } }; -inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn){ - out << "Node1: " << pn.startPhantom.forward_node_id << std::endl; - out << "Node2: " << pn.targetPhantom.reverse_node_id << std::endl; - out << "startCoord: " << pn.startPhantom.location << std::endl; - out << "targetCoord: " << pn.targetPhantom.location << std::endl; +inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) { + // out << "Node1: " << pn.startPhantom.forward_node_id << "\n"; + // out << "Node2: " << pn.targetPhantom.reverse_node_id << "\n"; + out << "start_coord: " << pn.startPhantom.location << "\n"; + out << "target_coord: " << pn.targetPhantom.location << std::endl; return out; } -inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn){ - out << "node1: " << pn.forward_node_id << ", node2: " << pn.reverse_node_id << ", name: " << pn.name_id << ", w1: " << pn.forward_weight << ", w2: " << pn.reverse_weight << ", ratio: " << pn.ratio << ", loc: " << pn.location; +inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn) { + out << "node1: " << pn.forward_node_id << ", " << + "node2: " << pn.reverse_node_id << ", " << + "name: " << pn.name_id << ", " << + "fwd-w: " << pn.forward_weight << ", " << + "rev-w: " << pn.reverse_weight << ", " << + "fwd-o: " << pn.forward_offset << ", " << + "rev-o: " << pn.reverse_offset << ", " << + "ratio: " << pn.ratio << ", " << + "geom: " << pn.packed_geometry_id << ", " << + "pos: " << pn.fwd_segment_position << ", " << + "loc: " << pn.location; return out; } diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 4ea337f2a..96ec16a37 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -292,12 +292,17 @@ public: // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); super::UnpackPath( + // -- packed input packed_shortest_path, + // -- start of route + phantom_node_pair.startPhantom.packed_geometry_id, phantom_node_pair.startPhantom.fwd_segment_position, (packed_shortest_path.front() != phantom_node_pair.startPhantom.forward_node_id), + // -- end of route phantom_node_pair.targetPhantom.packed_geometry_id, phantom_node_pair.targetPhantom.fwd_segment_position, (packed_shortest_path.back() != phantom_node_pair.targetPhantom.forward_node_id), + // -- unpacked output raw_route_data.unpacked_path_segments.front() ); raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; @@ -361,7 +366,8 @@ private: // unpack, supply correct offsets to packed start and end nodes. super::UnpackPath( packed_s_v_path, - 0, false, SPECIAL_EDGEID, 0, false, //TODO: replace by real offsets + SPECIAL_EDGEID, 0, false, //TODO: replace with actual data + SPECIAL_EDGEID, 0, false, //TODO: replace with actual data unpacked_path ); } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 6e423f19f..fb479ce2b 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -140,6 +140,7 @@ public: //TODO: refactor parameters to only edge ids for start and end inline void UnpackPath( const std::vector & packed_path, + const unsigned packed_geometry_id_of_first_edge, const int fwd_index_offset, const bool start_traversed_in_reverse, const unsigned packed_geometry_id_of_last_edge, @@ -255,10 +256,18 @@ public: } if(SPECIAL_EDGEID != packed_geometry_id_of_last_edge) { SimpleLogger().Write(logDEBUG) << "unpacking last segment " << packed_geometry_id_of_last_edge; + SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); std::vector id_vector; facade->GetUncompressedGeometry(packed_geometry_id_of_last_edge, id_vector); - const int start_index = 0; - const int end_index = rev_index_offset; + if( target_traversed_in_reverse ) { + std::reverse(id_vector.begin(), id_vector.end() ); + } + SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); + const bool start_and_end_on_same_edge = (packed_geometry_id_of_first_edge == packed_geometry_id_of_last_edge) && unpacked_path.empty(); + const int start_index = ( start_and_end_on_same_edge ? id_vector.size() - fwd_index_offset : 0 ); + const int end_index = (target_traversed_in_reverse ? id_vector.size() - rev_index_offset : rev_index_offset); + + SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; BOOST_ASSERT( start_index >= 0 ); BOOST_ASSERT( start_index <= end_index ); diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index bab359ddd..daefdd5e0 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -364,8 +364,7 @@ public: BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); super::UnpackPath( packed_legs1[i], - ( at_beginning ? start_offset : 0), - false, + SPECIAL_EDGEID, ( at_beginning ? start_offset : 0), false, SPECIAL_EDGEID, 0, false, raw_route_data.unpacked_path_segments[i] ); diff --git a/Server/RequestHandler.cpp b/Server/RequestHandler.cpp index 9dceb6852..664bdf35a 100644 --- a/Server/RequestHandler.cpp +++ b/Server/RequestHandler.cpp @@ -25,14 +25,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "RequestHandler.h" #include "APIGrammar.h" +#include "RequestHandler.h" +#include "Http/Request.h" #include "../Library/OSRM.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include "../typedefs.h" +#include #include #include diff --git a/Server/RequestHandler.h b/Server/RequestHandler.h index 320c0b5b7..ae7591aea 100644 --- a/Server/RequestHandler.h +++ b/Server/RequestHandler.h @@ -28,10 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef REQUEST_HANDLER_H #define REQUEST_HANDLER_H -#include "Http/Request.h" - -#include - #include #include @@ -41,6 +37,11 @@ struct APIGrammar; struct RouteParameters; class OSRM; +namespace http { + class Reply; + struct Request; +} + class RequestHandler : private boost::noncopyable { public: From 985270bb02743c36ba884b92230b00efd455e68c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 5 Mar 2014 19:16:17 +0100 Subject: [PATCH 19/89] parse maxspeed in LUA --- profiles/bicycle.lua | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index 08f78b8ce..b935bafbc 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -96,6 +96,22 @@ turn_penalty = 60 turn_bias = 1.4 -- End of globals + +local function parse_maxspeed(source) + if not source then + return 0 + end + local n = tonumber(source:match("%d*")) + if not n then + n = 0 + end + if string.match(source, "mph") or string.match(source, "mp/h") then + n = (n*1609)/1000; + end + return n +end + + function get_exceptions(vector) for i,v in ipairs(restriction_exception_tags) do vector:Add(v) @@ -107,6 +123,29 @@ function node_function (node) local access = Access.find_access_tag(node, access_tags_hierachy) local traffic_signal = node.tags:Find("highway") + -- flag node if it carries a traffic light + if traffic_signal == "traffic_signals" then + node.traffic_light = true + end + + -- parse access and barrier tags + if access and access ~= "" then + if access_tag_blacklist[access] then + node.bollard = true + else + node.bollard = false + end + elseif barrier and barrier ~= "" then + if barrier_whitelist[barrier] then + node.bollard = false + else + node.bollard = true + end + end + + -- return 1 +end + -- flag node if it carries a traffic light if traffic_signal == "traffic_signals" then node.traffic_light = true @@ -159,7 +198,6 @@ function way_function (way) return 0 end - -- other tags local name = way.tags:Find("name") local ref = way.tags:Find("ref") From 3b29eeb6b6c00e9a42fce6ca6b644cb2a1620b91 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 5 Mar 2014 19:17:19 +0100 Subject: [PATCH 20/89] unpacking start and target edge fixes plus some refactoring --- RoutingAlgorithms/AlternativePathRouting.h | 627 +++++++++++++-------- RoutingAlgorithms/BasicRoutingInterface.h | 11 +- RoutingAlgorithms/ShortestPathRouting.h | 77 ++- 3 files changed, 441 insertions(+), 274 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 96ec16a37..d04c4b4f9 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -25,15 +25,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ALTERNATIVEROUTES_H_ -#define ALTERNATIVEROUTES_H_ +#ifndef ALTERNATIVE_PATH_ROUTING_H +#define ALTERNATIVE_PATH_ROUTING_H #include "BasicRoutingInterface.h" #include "../DataStructures/SearchEngineData.h" +#include "../Util/TimingUtil.h" +#include #include #include -#include + #include const double VIAPATH_ALPHA = 0.15; @@ -74,7 +76,7 @@ public: engine_working_data(engine_working_data) { } - ~AlternativeRouting() {} + virtual ~AlternativeRouting() {} void operator() ( const PhantomNodes & phantom_node_pair, @@ -83,8 +85,8 @@ public: if( //phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() || phantom_node_pair.PhantomNodesHaveEqualLocation() ) { - raw_route_data.lengthOfShortestPath = INT_MAX; - raw_route_data.lengthOfAlternativePath = INT_MAX; + // raw_route_data.lengthOfShortestPath = INVALID_EDGE_WEIGHT; + // raw_route_data.lengthOfAlternativePath = INVALID_EDGE_WEIGHT; SimpleLogger().Write(logDEBUG) << "not executing path search"; return; } @@ -94,6 +96,7 @@ public: std::vector forward_search_space; std::vector reverse_search_space; + //Init queues, semi-expensive because access to TSS invokes a sys-call engine_working_data.InitializeOrClearFirstThreadLocalStorage( super::facade->GetNumberOfNodes() @@ -153,6 +156,8 @@ public: phantom_node_pair.targetPhantom ); + SimpleLogger().Write(logDEBUG) << "fwd_offset: " << forward_offset << ", reverse_offset: " << reverse_offset; + //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()){ @@ -179,6 +184,7 @@ public: } } sort_unique_resize(via_node_candidate_list); + SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; std::vector packed_forward_path; std::vector packed_reverse_path; @@ -202,7 +208,10 @@ public: BOOST_FOREACH(const SearchSpaceEdge & current_edge, forward_search_space) { const NodeID u = current_edge.first; const NodeID v = current_edge.second; - if(packed_forward_path.size() < index_into_forward_path && current_edge == forward_search_space[index_into_forward_path]) { + if( + ( packed_forward_path.size() < index_into_forward_path ) && + ( current_edge == forward_search_space[index_into_forward_path] ) + ) { //current_edge is on shortest path => sharing(u):=queue.GetKey(u); ++index_into_forward_path; approximated_forward_sharing[v] = forward_heap1.GetKey(u); @@ -217,65 +226,87 @@ public: BOOST_FOREACH(const SearchSpaceEdge & current_edge, reverse_search_space) { const NodeID u = current_edge.first; const NodeID v = current_edge.second; - if(packed_reverse_path.size() < index_into_reverse_path && current_edge == reverse_search_space[index_into_reverse_path]) { + if( + ( packed_reverse_path.size() < index_into_reverse_path ) && + ( current_edge == reverse_search_space[index_into_reverse_path] ) + ) { //current_edge is on shortest path => sharing(u):=queue.GetKey(u); ++index_into_reverse_path; approximated_reverse_sharing[v] = reverse_heap1.GetKey(u); } else { //sharing (s) = sharing (t) - boost::unordered_map::const_iterator rev_iterator = approximated_reverse_sharing.find(u); + boost::unordered_map::const_iterator rev_iterator = approximated_reverse_sharing.find(u); const int rev_sharing = (rev_iterator != approximated_reverse_sharing.end()) ? rev_iterator->second : 0; approximated_reverse_sharing[v] = rev_sharing; } } - std::vector nodes_that_passed_preselection; + + SimpleLogger().Write(logDEBUG) << "fwd_search_space size: " << forward_search_space.size() << ", marked " << approximated_forward_sharing.size() << " nodes"; + SimpleLogger().Write(logDEBUG) << "rev_search_space size: " << reverse_search_space.size() << ", marked " << approximated_reverse_sharing.size() << " nodes"; + + std::vector preselected_node_list; BOOST_FOREACH(const NodeID node, via_node_candidate_list) { boost::unordered_map::const_iterator fwd_iterator = approximated_forward_sharing.find(node); const int fwd_sharing = (fwd_iterator != approximated_forward_sharing.end()) ? fwd_iterator->second : 0; boost::unordered_map::const_iterator rev_iterator = approximated_reverse_sharing.find(node); const int rev_sharing = (rev_iterator != approximated_reverse_sharing.end()) ? rev_iterator->second : 0; - int approximated_sharing = fwd_sharing + rev_sharing; - int approximated_length = forward_heap1.GetKey(node)+reverse_heap1.GetKey(node); - bool lengthPassed = (approximated_length < upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)); - bool sharingPassed = (approximated_sharing <= upper_bound_to_shortest_path_distance*VIAPATH_GAMMA); - bool stretchPassed = approximated_length - approximated_sharing < (1.+VIAPATH_EPSILON)*(upper_bound_to_shortest_path_distance-approximated_sharing); + const int approximated_sharing = fwd_sharing + rev_sharing; + const int approximated_length = forward_heap1.GetKey(node) + reverse_heap1.GetKey(node); + const bool length_passes = (approximated_length < upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)); + const bool sharing_passes = (approximated_sharing <= upper_bound_to_shortest_path_distance*VIAPATH_GAMMA); + const bool stretch_passes = (approximated_length - approximated_sharing) < ((1.+VIAPATH_EPSILON)*(upper_bound_to_shortest_path_distance-approximated_sharing)); - if(lengthPassed && sharingPassed && stretchPassed) { - nodes_that_passed_preselection.push_back(node); + if( length_passes && sharing_passes && stretch_passes ) { + preselected_node_list.push_back(node); } } + SimpleLogger().Write() << preselected_node_list.size() << " passed preselection"; + std::vector & packed_shortest_path = packed_forward_path; std::reverse(packed_shortest_path.begin(), packed_shortest_path.end()); packed_shortest_path.push_back(middle_node); - packed_shortest_path.insert(packed_shortest_path.end(),packed_reverse_path.begin(), packed_reverse_path.end()); - std::vector rankedCandidates; + packed_shortest_path.insert( + packed_shortest_path.end(), + packed_reverse_path.begin(), + packed_reverse_path.end() + ); + std::vector ranked_candidates_list; //prioritizing via nodes for deep inspection - BOOST_FOREACH(const NodeID node, nodes_that_passed_preselection) { - int lengthOfViaPath = 0, sharingOfViaPath = 0; - computeLengthAndSharingOfViaPath(node, &lengthOfViaPath, &sharingOfViaPath, forward_offset+reverse_offset, packed_shortest_path); - if(sharingOfViaPath <= upper_bound_to_shortest_path_distance*VIAPATH_GAMMA) { - rankedCandidates.push_back(RankedCandidateNode(node, lengthOfViaPath, sharingOfViaPath)); + BOOST_FOREACH(const NodeID node, preselected_node_list) { + int length_of_via_path = 0, sharing_of_via_path = 0; + ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path, forward_offset+reverse_offset, packed_shortest_path); + const int maximum_allowed_sharing = upper_bound_to_shortest_path_distance*VIAPATH_GAMMA; + if( sharing_of_via_path <= maximum_allowed_sharing ) { + ranked_candidates_list.push_back( + RankedCandidateNode( + node, + length_of_via_path, + sharing_of_via_path + ) + ); } } - std::sort(rankedCandidates.begin(), rankedCandidates.end()); + std::sort( + ranked_candidates_list.begin(), + ranked_candidates_list.end() + ); - NodeID selectedViaNode = UINT_MAX; - int lengthOfViaPath = INT_MAX; - NodeID s_v_middle = UINT_MAX, v_t_middle = UINT_MAX; - BOOST_FOREACH(const RankedCandidateNode & candidate, rankedCandidates){ - if(viaNodeCandidatePasses_T_Test(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate, forward_offset+reverse_offset, upper_bound_to_shortest_path_distance, &lengthOfViaPath, &s_v_middle, &v_t_middle)) { + NodeID selected_via_node = SPECIAL_NODEID; + int length_of_via_path = INVALID_EDGE_WEIGHT; + NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID; + BOOST_FOREACH(const RankedCandidateNode & candidate, ranked_candidates_list){ + if(ViaNodeCandidatePassesTTest(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate, forward_offset+reverse_offset, upper_bound_to_shortest_path_distance, &length_of_via_path, &s_v_middle, &v_t_middle)) { // select first admissable - selectedViaNode = candidate.node; + selected_via_node = candidate.node; break; } } - //Unpack shortest path and alternative, if they exist - if(INT_MAX != upper_bound_to_shortest_path_distance) { + if( INVALID_EDGE_WEIGHT != upper_bound_to_shortest_path_distance ) { BOOST_ASSERT( !packed_shortest_path.empty() ); raw_route_data.unpacked_path_segments.resize(1); // SimpleLogger().Write() << "fwd offset1: " << phantom_node_pair.startPhantom.fwd_segment_position; @@ -306,48 +337,59 @@ public: raw_route_data.unpacked_path_segments.front() ); raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; - } else { - //TODO: kill this branch by initialization - raw_route_data.lengthOfShortestPath = INT_MAX; + SimpleLogger().Write(logDEBUG) << "upper_bound_to_shortest_path_distance: " << upper_bound_to_shortest_path_distance; } - if(selectedViaNode != UINT_MAX) { - RetrieveAndUnpackAlternatePath( + if(SPECIAL_NODEID != selected_via_node ) { + std::vector packed_alternate_path; + // retrieve alternate path + RetrievePackedAlternatePath( forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, s_v_middle, v_t_middle, + packed_alternate_path + ); + + // unpack the alternate path + super::UnpackPath( + packed_alternate_path, + phantom_node_pair.startPhantom.packed_geometry_id, + phantom_node_pair.startPhantom.fwd_segment_position, + (packed_alternate_path.front() != phantom_node_pair.startPhantom.forward_node_id), + phantom_node_pair.targetPhantom.packed_geometry_id, + phantom_node_pair.targetPhantom.fwd_segment_position, + (packed_alternate_path.back() != phantom_node_pair.targetPhantom.forward_node_id), raw_route_data.unpacked_alternative ); - raw_route_data.lengthOfAlternativePath = lengthOfViaPath; - } else { - //TODO: kill this branch by initialization - raw_route_data.lengthOfAlternativePath = INT_MAX; + + raw_route_data.lengthOfAlternativePath = length_of_via_path; + SimpleLogger().Write(logDEBUG) << "length_of_via_path: " << length_of_via_path; } } private: - //unpack by exploring search spaces from v - inline void RetrieveAndUnpackAlternatePath( + //unpack alternate by exploring search spaces from v + inline void RetrievePackedAlternatePath( const QueryHeap & forward_heap1, const QueryHeap & reverse_heap1, const QueryHeap & forward_heap2, const QueryHeap & reverse_heap2, const NodeID s_v_middle, const NodeID v_t_middle, - std::vector & unpacked_path + std::vector & packed_path ) const { //fetch packed path [s,v) - std::vector packed_s_v_path, packed_v_t_path; + std::vector packed_v_t_path; super::RetrievePackedPathFromHeap( forward_heap1, reverse_heap2, s_v_middle, - packed_s_v_path + packed_path ); - packed_s_v_path.pop_back(); //remove v, other we get it twice + packed_path.pop_back(); //remove middle node. It's in both half-paths //fetch patched path [v,t] super::RetrievePackedPathFromHeap( @@ -357,22 +399,14 @@ private: packed_v_t_path ); - packed_s_v_path.insert( - packed_s_v_path.end(), + packed_path.insert( + packed_path.end(), packed_v_t_path.begin(), packed_v_t_path.end() ); - - // unpack, supply correct offsets to packed start and end nodes. - super::UnpackPath( - packed_s_v_path, - SPECIAL_EDGEID, 0, false, //TODO: replace with actual data - SPECIAL_EDGEID, 0, false, //TODO: replace with actual data - unpacked_path - ); } - inline void computeLengthAndSharingOfViaPath(const NodeID via_node, int *real_length_of_via_path, int *sharing_of_via_path, + inline void ComputeLengthAndSharingOfViaPath(const NodeID via_node, int *real_length_of_via_path, int *sharing_of_via_path, 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 @@ -380,80 +414,114 @@ private: super::facade->GetNumberOfNodes() ); - QueryHeap & existingForwardHeap = *engine_working_data.forwardHeap; - QueryHeap & existingBackwardHeap = *engine_working_data.backwardHeap; - QueryHeap & newForwardHeap = *engine_working_data.forwardHeap2; - QueryHeap & newBackwardHeap = *engine_working_data.backwardHeap2; + QueryHeap & existing_forward_heap = *engine_working_data.forwardHeap; + QueryHeap & existing_reverse_heap = *engine_working_data.backwardHeap; + QueryHeap & new_forward_heap = *engine_working_data.forwardHeap2; + QueryHeap & new_reverse_heap = *engine_working_data.backwardHeap2; - std::vector < NodeID > packed_s_v_path; - std::vector < NodeID > packed_v_t_path; + std::vector packed_s_v_path; + std::vector packed_v_t_path; - std::vector partiallyUnpacked_shortest_path; - std::vector partiallyUnpackedViaPath; + std::vector partially_unpacked_shortest_path; + std::vector partially_unpacked_via_path; - NodeID s_v_middle = UINT_MAX; - int upperBoundFor_s_vPath = INT_MAX;//compute path by reusing forward search from s - newBackwardHeap.Insert(via_node, 0, via_node); - while (0 < newBackwardHeap.Size()) { - super::RoutingStep(newBackwardHeap, existingForwardHeap, &s_v_middle, &upperBoundFor_s_vPath, 2 * offset, false); + NodeID s_v_middle = SPECIAL_NODEID; + int upper_bound_s_v_path_length = INVALID_EDGE_WEIGHT; + new_reverse_heap.Insert(via_node, 0, via_node); + //compute path by reusing forward search from s + while( !new_reverse_heap.Empty() ) { + super::RoutingStep( + new_reverse_heap, + existing_forward_heap, + &s_v_middle, + &upper_bound_s_v_path_length, + 2 * offset, + false + ); } //compute path by reusing backward search from node t - NodeID v_t_middle = UINT_MAX; - int upperBoundFor_v_tPath = INT_MAX; - newForwardHeap.Insert(via_node, 0, via_node); - while (0 < newForwardHeap.Size() ) { - super::RoutingStep(newForwardHeap, existingBackwardHeap, &v_t_middle, &upperBoundFor_v_tPath, 2 * offset, true); + NodeID v_t_middle = SPECIAL_NODEID; + int upper_bound_of_v_t_path_length = INVALID_EDGE_WEIGHT; + new_forward_heap.Insert(via_node, 0, via_node); + while(!new_forward_heap.Empty() ) { + super::RoutingStep( + new_forward_heap, + existing_reverse_heap, + &v_t_middle, + &upper_bound_of_v_t_path_length, + 2 * offset, + true + ); } - *real_length_of_via_path = upperBoundFor_s_vPath + upperBoundFor_v_tPath; + *real_length_of_via_path = upper_bound_s_v_path_length + upper_bound_of_v_t_path_length; - if(UINT_MAX == s_v_middle || UINT_MAX == v_t_middle) + if( SPECIAL_NODEID == s_v_middle || SPECIAL_NODEID == v_t_middle ) { return; + } //retrieve packed paths - super::RetrievePackedPathFromHeap(existingForwardHeap, newBackwardHeap, s_v_middle, packed_s_v_path); - super::RetrievePackedPathFromHeap(newForwardHeap, existingBackwardHeap, v_t_middle, packed_v_t_path); + super::RetrievePackedPathFromHeap( + existing_forward_heap, + new_reverse_heap, + s_v_middle, + packed_s_v_path + ); + super::RetrievePackedPathFromHeap( + new_forward_heap, + existing_reverse_heap, + v_t_middle, + packed_v_t_path + ); //partial unpacking, compute sharing //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]) { + const unsigned s_v_min_path_size = std::min( packed_s_v_path.size(), packed_shortest_path.size()) - 1; + for( + unsigned i = 0; + i < s_v_min_path_size; + ++i + ) { + if(packed_s_v_path[i] == packed_shortest_path[i] && packed_s_v_path[i + 1] == packed_shortest_path[i + 1]) { 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); - super::UnpackEdge(packed_shortest_path[i], packed_shortest_path[i+1], partiallyUnpacked_shortest_path); + if( packed_s_v_path[i] == packed_shortest_path[i] ) { + super::UnpackEdge(packed_s_v_path[i], packed_s_v_path[i+1], partially_unpacked_via_path); + super::UnpackEdge(packed_shortest_path[i], packed_shortest_path[i+1], partially_unpacked_shortest_path); break; } } } //traverse partially unpacked edge and note common prefix - for (int i = 0, lengthOfPackedPath = std::min( partiallyUnpackedViaPath.size(), partiallyUnpacked_shortest_path.size()) - 1; (i < lengthOfPackedPath) && (partiallyUnpackedViaPath[i] == partiallyUnpacked_shortest_path[i] && partiallyUnpackedViaPath[i+1] == partiallyUnpacked_shortest_path[i+1]); ++i) { - EdgeID edgeID = facade->FindEdgeInEitherDirection(partiallyUnpackedViaPath[i], partiallyUnpackedViaPath[i+1]); + for (int i = 0, packed_path_length = std::min( partially_unpacked_via_path.size(), partially_unpacked_shortest_path.size()) - 1; (i < packed_path_length) && (partially_unpacked_via_path[i] == partially_unpacked_shortest_path[i] && partially_unpacked_via_path[i+1] == partially_unpacked_shortest_path[i+1]); ++i) { + EdgeID edgeID = facade->FindEdgeInEitherDirection(partially_unpacked_via_path[i], partially_unpacked_via_path[i+1]); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } //Second, partially unpack v-->t in reverse order until paths deviate and note lengths - int viaPathIndex = packed_v_t_path.size() - 1; - 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]) { - EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[viaPathIndex - 1], packed_v_t_path[viaPathIndex]); + int via_path_index = packed_v_t_path.size() - 1; + int shortest_path_index = packed_shortest_path.size() - 1; + for (; + via_path_index > 0 && shortest_path_index > 0; + --via_path_index,--shortest_path_index + ) { + if (packed_v_t_path[via_path_index-1] == packed_shortest_path[shortest_path_index-1] && packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) { + EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[via_path_index-1], packed_v_t_path[via_path_index]); *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); - super::UnpackEdge(packed_shortest_path[shortestPathIndex-1] , packed_shortest_path[shortestPathIndex], partiallyUnpacked_shortest_path); + if (packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) { + super::UnpackEdge(packed_v_t_path[via_path_index-1], packed_v_t_path[via_path_index], partially_unpacked_via_path); + super::UnpackEdge(packed_shortest_path[shortest_path_index-1] , packed_shortest_path[shortest_path_index], partially_unpacked_shortest_path); break; } } } - viaPathIndex = partiallyUnpackedViaPath.size() - 1; - shortestPathIndex = partiallyUnpacked_shortest_path.size() - 1; - for (; viaPathIndex > 0 && shortestPathIndex > 0; --viaPathIndex,--shortestPathIndex) { - if (partiallyUnpackedViaPath[viaPathIndex - 1] == partiallyUnpacked_shortest_path[shortestPathIndex - 1] && partiallyUnpackedViaPath[viaPathIndex] == partiallyUnpacked_shortest_path[shortestPathIndex]) { - EdgeID edgeID = facade->FindEdgeInEitherDirection( partiallyUnpackedViaPath[viaPathIndex - 1], partiallyUnpackedViaPath[viaPathIndex]); + via_path_index = partially_unpacked_via_path.size()-1; + shortest_path_index = partially_unpacked_shortest_path.size()-1; + for (; via_path_index > 0 && shortest_path_index > 0; --via_path_index,--shortest_path_index) { + if (partially_unpacked_via_path[via_path_index-1] == partially_unpacked_shortest_path[shortest_path_index-1] && partially_unpacked_via_path[via_path_index] == partially_unpacked_shortest_path[shortest_path_index]) { + EdgeID edgeID = facade->FindEdgeInEitherDirection( partially_unpacked_via_path[via_path_index-1], partially_unpacked_via_path[via_path_index]); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { break; @@ -462,241 +530,322 @@ private: //finished partial unpacking spree! Amount of sharing is stored to appropriate pointer variable } - inline int approximateAmountOfSharing(const NodeID middleNodeIDOfAlternativePath, QueryHeap & _forwardHeap, QueryHeap & _backwardHeap, const std::vector & packed_shortest_path) { - std::vector packedAlternativePath; - super::RetrievePackedPathFromHeap(_forwardHeap, _backwardHeap, middleNodeIDOfAlternativePath, packedAlternativePath); + // inline int approximateAmountOfSharing( + // const NodeID alternate_path_middle_node_id, + // QueryHeap & forward_heap, + // QueryHeap & reverse_heap, + // const std::vector & packed_shortest_path + // ) const { + // std::vector packed_alternate_path; + // super::RetrievePackedPathFromHeap( + // forward_heap, + // reverse_heap, + // alternate_path_middle_node_id, + // packed_alternate_path + // ); - if(packed_shortest_path.size() < 2 || packedAlternativePath.size() < 2) - return 0; + // if(packed_shortest_path.size() < 2 || packed_alternate_path.size() < 2) { + // return 0; + // } - int sharing = 0; - int aindex = 0; - //compute forward sharing - while( (packedAlternativePath[aindex] == packed_shortest_path[aindex]) && (packedAlternativePath[aindex+1] == packed_shortest_path[aindex+1]) ) { - // SimpleLogger().Write() << "retrieving edge (" << packedAlternativePath[aindex] << "," << packedAlternativePath[aindex+1] << ")"; - EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex+1]); - sharing += facade->GetEdgeData(edgeID).distance; - ++aindex; - } + // int sharing = 0; + // int aindex = 0; + // //compute forward sharing + // while( (packed_alternate_path[aindex] == packed_shortest_path[aindex]) && (packed_alternate_path[aindex+1] == packed_shortest_path[aindex+1]) ) { + // // SimpleLogger().Write() << "retrieving edge (" << packed_alternate_path[aindex] << "," << packed_alternate_path[aindex+1] << ")"; + // EdgeID edgeID = facade->FindEdgeInEitherDirection(packed_alternate_path[aindex], packed_alternate_path[aindex+1]); + // sharing += facade->GetEdgeData(edgeID).distance; + // ++aindex; + // } - aindex = packedAlternativePath.size()-1; - int bindex = packed_shortest_path.size()-1; - //compute backward sharing - while( aindex > 0 && bindex > 0 && (packedAlternativePath[aindex] == packed_shortest_path[bindex]) && (packedAlternativePath[aindex-1] == packed_shortest_path[bindex-1]) ) { - EdgeID edgeID = facade->FindEdgeInEitherDirection(packedAlternativePath[aindex], packedAlternativePath[aindex-1]); - sharing += facade->GetEdgeData(edgeID).distance; - --aindex; --bindex; - } - return sharing; - } + // aindex = packed_alternate_path.size()-1; + // int bindex = packed_shortest_path.size()-1; + // //compute backward sharing + // while( aindex > 0 && bindex > 0 && (packed_alternate_path[aindex] == packed_shortest_path[bindex]) && (packed_alternate_path[aindex-1] == packed_shortest_path[bindex-1]) ) { + // EdgeID edgeID = facade->FindEdgeInEitherDirection(packed_alternate_path[aindex], packed_alternate_path[aindex-1]); + // sharing += facade->GetEdgeData(edgeID).distance; + // --aindex; --bindex; + // } + // return sharing; + // } - template + template inline void AlternativeRoutingStep( - QueryHeap & _forward_heap, - QueryHeap & _reverse_heap, - NodeID *middle_node, - int *upper_bound_to_shortest_path_distance, - std::vector& searchSpaceIntersection, + QueryHeap & forward_heap, + QueryHeap & reverse_heap, + NodeID * middle_node, + int * upper_bound_to_shortest_path_distance, + std::vector & search_space_intersection, std::vector & search_space, - const int edgeBasedOffset - ) const { - const NodeID node = _forward_heap.DeleteMin(); - const int distance = _forward_heap.GetKey(node); - int scaledDistance = (distance-edgeBasedOffset)/(1.+VIAPATH_EPSILON); - if(scaledDistance > *upper_bound_to_shortest_path_distance){ - _forward_heap.DeleteAll(); + const int edge_expansion_offset + ) const { + const NodeID node = forward_heap.DeleteMin(); + const int distance = forward_heap.GetKey(node); + const int scaled_distance = (distance-edge_expansion_offset)/(1.+VIAPATH_EPSILON); + if( scaled_distance > *upper_bound_to_shortest_path_distance ){ + forward_heap.DeleteAll(); return; } - search_space.push_back(std::make_pair(_forward_heap.GetData( node ).parent, node)); + search_space.push_back( + std::make_pair(forward_heap.GetData( node ).parent, node) + ); - if(_reverse_heap.WasInserted(node) ){ - searchSpaceIntersection.push_back(node); + if( reverse_heap.WasInserted(node) ) { + search_space_intersection.push_back(node); - const int newDistance = _reverse_heap.GetKey(node) + distance; - if(newDistance < *upper_bound_to_shortest_path_distance ){ - if(newDistance>=0 ) { + const int new_distance = reverse_heap.GetKey(node) + distance; + if( new_distance < *upper_bound_to_shortest_path_distance ){ + if( new_distance >= 0 ) { *middle_node = node; - *upper_bound_to_shortest_path_distance = newDistance; + *upper_bound_to_shortest_path_distance = new_distance; } } } - for ( EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); edge++ ) { + for( + EdgeID edge = facade->BeginEdges(node); + edge < facade->EndEdges(node); + ++edge + ) { const EdgeData & data = facade->GetEdgeData(edge); - bool forwardDirectionFlag = (forwardDirection ? data.forward : data.backward ); - if(forwardDirectionFlag) { + const bool edge_is_forward_directed = (is_forward_directed ? data.forward : data.backward ); + if( edge_is_forward_directed ) { const NodeID to = facade->GetTarget(edge); - const int edgeWeight = data.distance; + const int edge_weight = data.distance; - assert( edgeWeight > 0 ); - const int toDistance = distance + edgeWeight; + BOOST_ASSERT( edge_weight > 0 ); + const int to_distance = distance + edge_weight; //New Node discovered -> Add to Heap + Node Info Storage - if ( !_forward_heap.WasInserted( to ) ) { - _forward_heap.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 < _forward_heap.GetKey( to ) ) { - _forward_heap.GetData( to ).parent = node; - _forward_heap.DecreaseKey( to, toDistance ); - //new parent + else if ( to_distance < forward_heap.GetKey( to ) ) { + // new parent + forward_heap.GetData( to ).parent = node; + // decreased distance + forward_heap.DecreaseKey( to, to_distance ); } } } } //conduct T-Test - inline bool viaNodeCandidatePasses_T_Test( QueryHeap& existingForwardHeap, QueryHeap& existingBackwardHeap, QueryHeap& newForwardHeap, QueryHeap& newBackwardHeap, const RankedCandidateNode& candidate, const int offset, const int lengthOfShortestPath, int * lengthOfViaPath, NodeID * s_v_middle, NodeID * v_t_middle) { - newForwardHeap.Clear(); - newBackwardHeap.Clear(); - std::vector < NodeID > packed_s_v_path; - std::vector < NodeID > packed_v_t_path; + inline bool ViaNodeCandidatePassesTTest( + QueryHeap& existing_forward_heap, + QueryHeap& existing_reverse_heap, + QueryHeap& new_forward_heap, + QueryHeap& new_reverse_heap, + const RankedCandidateNode& candidate, + const int offset, + const int lengthOfShortestPath, + int * length_of_via_path, + NodeID * s_v_middle, + NodeID * v_t_middle + ) const { + new_forward_heap.Clear(); + new_reverse_heap.Clear(); + std::vector packed_s_v_path; + std::vector packed_v_t_path; - *s_v_middle = UINT_MAX; - int upperBoundFor_s_vPath = INT_MAX; + *s_v_middle = SPECIAL_NODEID; + int upper_bound_s_v_path_length = INVALID_EDGE_WEIGHT; //compute path by reusing forward search from s - newBackwardHeap.Insert(candidate.node, 0, candidate.node); - while (newBackwardHeap.Size() > 0) { - super::RoutingStep(newBackwardHeap, existingForwardHeap, s_v_middle, &upperBoundFor_s_vPath, 2*offset, false); + new_reverse_heap.Insert(candidate.node, 0, candidate.node); + while (new_reverse_heap.Size() > 0) { + super::RoutingStep(new_reverse_heap, existing_forward_heap, s_v_middle, &upper_bound_s_v_path_length, 2*offset, false); } - if(INT_MAX == upperBoundFor_s_vPath) + if( INVALID_EDGE_WEIGHT == upper_bound_s_v_path_length ) { return false; + } //compute path by reusing backward search from t - *v_t_middle = UINT_MAX; - int upperBoundFor_v_tPath = INT_MAX; - newForwardHeap.Insert(candidate.node, 0, candidate.node); - while (newForwardHeap.Size() > 0) { - super::RoutingStep(newForwardHeap, existingBackwardHeap, v_t_middle, &upperBoundFor_v_tPath, 2*offset, true); + *v_t_middle = SPECIAL_NODEID; + int upper_bound_of_v_t_path_length = INVALID_EDGE_WEIGHT; + new_forward_heap.Insert(candidate.node, 0, candidate.node); + while (new_forward_heap.Size() > 0) { + super::RoutingStep(new_forward_heap, existing_reverse_heap, v_t_middle, &upper_bound_of_v_t_path_length, 2*offset, true); } - if(INT_MAX == upperBoundFor_v_tPath) + if( INVALID_EDGE_WEIGHT == upper_bound_of_v_t_path_length ){ return false; + } - *lengthOfViaPath = upperBoundFor_s_vPath + upperBoundFor_v_tPath; + *length_of_via_path = upper_bound_s_v_path_length + upper_bound_of_v_t_path_length; //retrieve packed paths - super::RetrievePackedPathFromHeap(existingForwardHeap, newBackwardHeap, *s_v_middle, packed_s_v_path); - super::RetrievePackedPathFromHeap(newForwardHeap, existingBackwardHeap, *v_t_middle, packed_v_t_path); + super::RetrievePackedPathFromHeap( + existing_forward_heap, + new_reverse_heap, + *s_v_middle, + packed_s_v_path + ); + + super::RetrievePackedPathFromHeap( + new_forward_heap, + existing_reverse_heap, + *v_t_middle, + packed_v_t_path + ); NodeID s_P = *s_v_middle, t_P = *v_t_middle; - if(UINT_MAX == s_P) { + if( SPECIAL_NODEID == s_P ) { return false; } - if(UINT_MAX == t_P) { + if( SPECIAL_NODEID == t_P ) { return false; } const int T_threshold = VIAPATH_EPSILON * lengthOfShortestPath; - int unpackedUntilDistance = 0; + int unpacked_until_distance = 0; - std::stack unpackStack; + std::stack unpack_stack; //Traverse path s-->v - for (unsigned i = packed_s_v_path.size() - 1; (i > 0) && unpackStack.empty(); --i) { - 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])); + for( + unsigned i = packed_s_v_path.size() - 1; + (i > 0) && unpack_stack.empty(); + --i + ) { + const EdgeID current_edge_id = facade->FindEdgeInEitherDirection( packed_s_v_path[i - 1], packed_s_v_path[i]); + const int length_of_current_edge = facade->GetEdgeData(current_edge_id).distance; + if( (length_of_current_edge + unpacked_until_distance) >= T_threshold ) { + unpack_stack.push( + std::make_pair(packed_s_v_path[i - 1], packed_s_v_path[i]) + ); } else { - unpackedUntilDistance += lengthOfCurrentEdge; + unpacked_until_distance += length_of_current_edge; s_P = packed_s_v_path[i - 1]; } } - while (!unpackStack.empty()) { - const SearchSpaceEdge viaPathEdge = unpackStack.top(); - unpackStack.pop(); - EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); - if(UINT_MAX == edgeIDInViaPath) + while( !unpack_stack.empty() ) { + const SearchSpaceEdge via_path_edge = unpack_stack.top(); + unpack_stack.pop(); + EdgeID edge_in_via_path_id = facade->FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second); + if( SPECIAL_EDGEID == edge_in_via_path_id ) { return false; - EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); - bool IsViaEdgeShortCut = currentEdgeData.shortcut; - if (IsViaEdgeShortCut) { - const NodeID middleOfViaPath = currentEdgeData.id; - EdgeID edgeIDOfSecondSegment = facade->FindEdgeInEitherDirection(middleOfViaPath, viaPathEdge.second); - int lengthOfSecondSegment = facade->GetEdgeData(edgeIDOfSecondSegment).distance; + } + + const EdgeData & current_edge_data = facade->GetEdgeData(edge_in_via_path_id); + const bool current_edge_is_shortcut = current_edge_data.shortcut; + if( current_edge_is_shortcut ) { + const NodeID via_path_middle_node_id = current_edge_data.id; + const EdgeID second_segment_edge_id = facade->FindEdgeInEitherDirection(via_path_middle_node_id, via_path_edge.second); + const int second_segment_length = facade->GetEdgeData(second_segment_edge_id).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) { - unpackStack.push(std::make_pair(middleOfViaPath, viaPathEdge.second)); + if (unpacked_until_distance + second_segment_length >= T_threshold) { + unpack_stack.push( + std::make_pair( + via_path_middle_node_id, + via_path_edge.second + ) + ); } else { - unpackedUntilDistance += lengthOfSecondSegment; - unpackStack.push(std::make_pair(viaPathEdge.first, middleOfViaPath)); + unpacked_until_distance += second_segment_length; + unpack_stack.push( + std::make_pair( + via_path_edge.first, + via_path_middle_node_id + ) + ); } } else { // edge is not a shortcut, set the start node for T-Test to end of edge. - unpackedUntilDistance += currentEdgeData.distance; - s_P = viaPathEdge.first; + unpacked_until_distance += current_edge_data.distance; + s_P = via_path_edge.first; } } - int lengthOfPathT_TestPath = unpackedUntilDistance; - unpackedUntilDistance = 0; + int t_test_path_length = unpacked_until_distance; + unpacked_until_distance = 0; //Traverse path s-->v - for (unsigned i = 0, lengthOfPackedPath = packed_v_t_path.size() - 1; (i < lengthOfPackedPath) && unpackStack.empty(); ++i) { + for( + unsigned i = 0, packed_path_length = packed_v_t_path.size() - 1; + (i < packed_path_length) && unpack_stack.empty(); + ++i + ) { 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])); + int length_of_current_edge = facade->GetEdgeData(edgeID).distance; + if (length_of_current_edge + unpacked_until_distance >= T_threshold) { + unpack_stack.push( std::make_pair(packed_v_t_path[i], packed_v_t_path[i + 1])); } else { - unpackedUntilDistance += lengthOfCurrentEdge; + unpacked_until_distance += length_of_current_edge; t_P = packed_v_t_path[i + 1]; } } - while (!unpackStack.empty()) { - const SearchSpaceEdge viaPathEdge = unpackStack.top(); - unpackStack.pop(); - EdgeID edgeIDInViaPath = facade->FindEdgeInEitherDirection(viaPathEdge.first, viaPathEdge.second); - if(UINT_MAX == edgeIDInViaPath) + while (!unpack_stack.empty()) { + const SearchSpaceEdge via_path_edge = unpack_stack.top(); + unpack_stack.pop(); + EdgeID edge_in_via_path_id = facade->FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second); + if(SPECIAL_EDGEID == edge_in_via_path_id) { return false; - EdgeData currentEdgeData = facade->GetEdgeData(edgeIDInViaPath); - const bool IsViaEdgeShortCut = currentEdgeData.shortcut; + } + + const EdgeData & current_edge_data = facade->GetEdgeData(edge_in_via_path_id); + const bool IsViaEdgeShortCut = current_edge_data.shortcut; if (IsViaEdgeShortCut) { - const NodeID middleOfViaPath = currentEdgeData.id; - EdgeID edgeIDOfFirstSegment = facade->FindEdgeInEitherDirection(viaPathEdge.first, middleOfViaPath); + const NodeID middleOfViaPath = current_edge_data.id; + EdgeID edgeIDOfFirstSegment = facade->FindEdgeInEitherDirection(via_path_edge.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)); + if (unpacked_until_distance + lengthOfFirstSegment >= T_threshold) { + unpack_stack.push( std::make_pair(via_path_edge.first, middleOfViaPath)); } else { - unpackedUntilDistance += lengthOfFirstSegment; - unpackStack.push( std::make_pair(middleOfViaPath, viaPathEdge.second)); + unpacked_until_distance += lengthOfFirstSegment; + unpack_stack.push( std::make_pair(middleOfViaPath, via_path_edge.second)); } } else { // edge is not a shortcut, set the start node for T-Test to end of edge. - unpackedUntilDistance += currentEdgeData.distance; - t_P = viaPathEdge.second; + unpacked_until_distance += current_edge_data.distance; + t_P = via_path_edge.second; } } - lengthOfPathT_TestPath += unpackedUntilDistance; + t_test_path_length += unpacked_until_distance; //Run actual T-Test query and compare if distances equal. engine_working_data.InitializeOrClearThirdThreadLocalStorage( super::facade->GetNumberOfNodes() ); - QueryHeap& forward_heap3 = *engine_working_data.forwardHeap3; - QueryHeap& backward_heap3 = *engine_working_data.backwardHeap3; - int _upperBound = INT_MAX; - NodeID middle = UINT_MAX; + QueryHeap & forward_heap3 = *engine_working_data.forwardHeap3; + QueryHeap & reverse_heap3 = *engine_working_data.backwardHeap3; + int upper_bound = INVALID_EDGE_WEIGHT; + NodeID middle = SPECIAL_NODEID; + forward_heap3.Insert(s_P, 0, s_P); - backward_heap3.Insert(t_P, 0, t_P); + reverse_heap3.Insert(t_P, 0, t_P); //exploration from s and t until deletemin/(1+epsilon) > _lengthOfShortestPath - while (forward_heap3.Size() + backward_heap3.Size() > 0) { - if (forward_heap3.Size() > 0) { - super::RoutingStep(forward_heap3, backward_heap3, &middle, &_upperBound, offset, true); + while( (forward_heap3.Size() + reverse_heap3.Size() ) > 0) { + if( !forward_heap3.Empty() ) { + super::RoutingStep( + forward_heap3, + reverse_heap3, + &middle, + &upper_bound, + offset, + true + ); } - if (backward_heap3.Size() > 0) { - super::RoutingStep(backward_heap3, forward_heap3, &middle, &_upperBound, offset, false); + if( !reverse_heap3.Empty() ) { + super::RoutingStep( + reverse_heap3, + forward_heap3, + &middle, + &upper_bound, + offset, + false + ); } } - return (_upperBound <= lengthOfPathT_TestPath); + return (upper_bound <= t_test_path_length); } }; -#endif /* ALTERNATIVEROUTES_H_ */ +#endif /* ALTERNATIVE_PATH_ROUTING_H */ diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index fb479ce2b..dd2798b44 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -200,10 +200,10 @@ public: } } } - BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge id invalid"); + BOOST_ASSERT_MSG(edge_weight != SPECIAL_EDGEID, "edge id invalid"); - BOOST_ASSERT( facade->EndEdges(edge.first) != smaller_edge_id ); + // BOOST_ASSERT( facade->EndEdges(edge.first) != smaller_edge_id ); const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); if( ed.shortcut ) {//unpack @@ -368,7 +368,7 @@ public: current_node_id = forward_heap.GetData(current_node_id).parent; packed_path.push_back(current_node_id); } - SimpleLogger().Write() << "parent of last node. " << forward_heap.GetData(current_node_id).parent; + // SimpleLogger().Write() << "parent of last node. " << forward_heap.GetData(current_node_id).parent; std::reverse(packed_path.begin(), packed_path.end()); packed_path.push_back(middle_node_id); current_node_id = middle_node_id; @@ -376,11 +376,6 @@ public: current_node_id = reverse_heap.GetData(current_node_id).parent; packed_path.push_back(current_node_id); } - - SimpleLogger().Write(logDEBUG) << "packed path"; - BOOST_FOREACH(NodeID node, packed_path) { - SimpleLogger().Write(logDEBUG) << "node: " << node; - } } //TODO: reorder parameters diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index daefdd5e0..6ff786a33 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -60,9 +60,9 @@ public: 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; + if( phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() ) { + // raw_route_data.lengthOfShortestPath = INT_MAX; + // raw_route_data.lengthOfAlternativePath = INT_MAX; return; } } @@ -104,9 +104,10 @@ public: middle2 = UINT_MAX; //insert new starting nodes into forward heap, adjusted by previous distances. - if(search_from_1st_node) { - BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX); - + if( + search_from_1st_node && + phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID + ) { forward_heap1.Insert( phantom_node_pair.startPhantom.forward_node_id, distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), @@ -118,8 +119,10 @@ public: phantom_node_pair.startPhantom.forward_node_id ); } - if(phantom_node_pair.startPhantom.isBidirected() && search_from_2nd_node) { - BOOST_ASSERT(phantom_node_pair.startPhantom.reverse_node_id != UINT_MAX); + if( + search_from_2nd_node && + phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID + ) { forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), @@ -133,15 +136,15 @@ public: } //insert new backward nodes into backward heap, unadjusted. - reverse_heap1.Insert( - phantom_node_pair.targetPhantom.forward_node_id, - phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.targetPhantom.forward_node_id - ); - BOOST_ASSERT(phantom_node_pair.targetPhantom.forward_node_id != UINT_MAX); + if( phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) { + reverse_heap1.Insert( + phantom_node_pair.targetPhantom.forward_node_id, + phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), + phantom_node_pair.targetPhantom.forward_node_id + ); + } - if(phantom_node_pair.targetPhantom.isBidirected() ) { - BOOST_ASSERT(phantom_node_pair.startPhantom.forward_node_id != UINT_MAX); + if( phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) { reverse_heap2.Insert( phantom_node_pair.targetPhantom.reverse_node_id, phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), @@ -207,17 +210,17 @@ public: //No path found for both target nodes? if( - (INT_MAX == local_upper_bound1) && - (INT_MAX == local_upper_bound2) + (INVALID_EDGE_WEIGHT == local_upper_bound1) && + (INVALID_EDGE_WEIGHT == local_upper_bound2) ) { - raw_route_data.lengthOfShortestPath = INT_MAX; - raw_route_data.lengthOfAlternativePath = INT_MAX; + raw_route_data.lengthOfShortestPath = INVALID_EDGE_WEIGHT; + raw_route_data.lengthOfAlternativePath = INVALID_EDGE_WEIGHT; return; } - if(UINT_MAX == middle1) { + if( SPECIAL_NODEID == middle1 ) { search_from_1st_node = false; } - if(UINT_MAX == middle2) { + if( SPECIAL_NODEID == middle2 ) { search_from_2nd_node = false; } @@ -234,7 +237,7 @@ public: BOOST_ASSERT( (unsigned)current_leg < packed_legs1.size() ); BOOST_ASSERT( (unsigned)current_leg < packed_legs2.size() ); - if(INT_MAX != local_upper_bound1) { + if( INVALID_EDGE_WEIGHT != local_upper_bound1 ) { super::RetrievePackedPathFromHeap( forward_heap1, reverse_heap1, @@ -243,7 +246,7 @@ public: ); } - if(INT_MAX != local_upper_bound2) { + if( INVALID_EDGE_WEIGHT != local_upper_bound2 ) { super::RetrievePackedPathFromHeap( forward_heap2, reverse_heap2, @@ -360,14 +363,34 @@ public: for(unsigned i = 0; i < packed_legs1.size(); ++i){ BOOST_ASSERT( !phantom_nodes_vector.empty() ); - bool at_beginning = (0 == i); + const bool at_beginning = (0 == i); + const bool at_end = (packed_legs1.size() == i+1); BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); + + super::UnpackPath( + // -- packed input packed_legs1[i], - SPECIAL_EDGEID, ( at_beginning ? start_offset : 0), false, - SPECIAL_EDGEID, 0, false, + // -- start of route + ( !at_beginning ? SPECIAL_EDGEID : phantom_nodes_vector.front().startPhantom.packed_geometry_id ), + ( !at_beginning ? 0 : phantom_nodes_vector.front().startPhantom.fwd_segment_position ), + ( !at_beginning ? false : (packed_legs1.front().front() != phantom_nodes_vector.front().startPhantom.forward_node_id) ), + // -- end of route + ( !at_end ? SPECIAL_EDGEID : phantom_nodes_vector.back().targetPhantom.packed_geometry_id ), + ( !at_end ? 0 : phantom_nodes_vector.back().targetPhantom.fwd_segment_position ), + ( !at_end ? false : (packed_legs1.back().back() != phantom_nodes_vector.back().targetPhantom.forward_node_id) ), + // -- unpacked output raw_route_data.unpacked_path_segments[i] ); + + + // // TODO: properly unpack first and last segments + // super::UnpackPath( + // packed_legs1[i], + // SPECIAL_EDGEID, ( at_beginning ? start_offset : 0), false, + // SPECIAL_EDGEID, 0, false, + // raw_route_data.unpacked_path_segments[i] + // ); } raw_route_data.lengthOfShortestPath = std::min(distance1, distance2); } From 0b3f3bdf9261f3b4a41bc96a20fca89295adc0c8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 18:03:47 +0100 Subject: [PATCH 21/89] fix test for borked lat/lons --- DataStructures/Coordinate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataStructures/Coordinate.cpp b/DataStructures/Coordinate.cpp index e34dc7f32..dc90b20e0 100644 --- a/DataStructures/Coordinate.cpp +++ b/DataStructures/Coordinate.cpp @@ -44,11 +44,11 @@ FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon) { - if(0 != (lat >> 30)) { + if(0 != (std::abs(lat) >> 30)) { std::bitset<32> y(lat); SimpleLogger().Write(logDEBUG) << "broken lat: " << lat << ", bits: " << y; } - if(0 != (lon >> 30)) { + if(0 != (std::abs(lon) >> 30)) { std::bitset<32> x(lon); SimpleLogger().Write(logDEBUG) << "broken lon: " << lon << ", bits: " << x; } From 09c76939f18f74ca7ca7e3cf6226f695ba588f82 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 18:05:22 +0100 Subject: [PATCH 22/89] minor code beauty issue --- DataStructures/PhantomNodes.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index bb8630462..46331ea62 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -99,7 +99,8 @@ struct PhantomNode { ) && (ratio >= 0.) && (ratio <= 1.) && - (name_id != std::numeric_limits::max()); + (name_id != std::numeric_limits::max() + ); } bool operator==(const PhantomNode & other) const { From 2a642975064a966010349197bbc9969492731bc6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 18:07:55 +0100 Subject: [PATCH 23/89] Forward decl to cut compile times --- Extractor/ExtractionHelperFunctions.h | 16 ++++++++-------- Extractor/ExtractorCallbacks.cpp | 18 +++++++----------- Extractor/ExtractorCallbacks.h | 8 +++----- Extractor/PBFParser.cpp | 1 + Extractor/PBFParser.h | 12 ++++++------ Extractor/XMLParser.cpp | 2 ++ Extractor/XMLParser.h | 5 ++--- 7 files changed, 29 insertions(+), 33 deletions(-) diff --git a/Extractor/ExtractionHelperFunctions.h b/Extractor/ExtractionHelperFunctions.h index c0b74bdb3..d284efdd7 100644 --- a/Extractor/ExtractionHelperFunctions.h +++ b/Extractor/ExtractionHelperFunctions.h @@ -75,13 +75,13 @@ inline unsigned parseDuration(const std::string &s) { return UINT_MAX; } -inline int parseMaxspeed(std::string input) { //call-by-value on purpose. - boost::algorithm::to_lower(input); - int n = stringToInt(input); - if (input.find("mph") != std::string::npos || input.find("mp/h") != std::string::npos) { - n = (n*1609)/1000; - } - return n; -} +// inline int parseMaxspeed(std::string input) { //call-by-value on purpose. +// boost::algorithm::to_lower(input); +// int n = stringToInt(input); +// if (input.find("mph") != std::string::npos || input.find("mp/h") != std::string::npos) { +// n = (n*1609)/1000; +// } +// return n; +// } #endif /* EXTRACTIONHELPERFUNCTIONS_H_ */ diff --git a/Extractor/ExtractorCallbacks.cpp b/Extractor/ExtractorCallbacks.cpp index 0dc5ac8aa..9ac9cb1cb 100644 --- a/Extractor/ExtractorCallbacks.cpp +++ b/Extractor/ExtractorCallbacks.cpp @@ -28,32 +28,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ExtractorCallbacks.h" #include "ExtractionContainers.h" -#include "ExtractionHelperFunctions.h" #include "ExtractionWay.h" #include "../DataStructures/Restriction.h" +#include "../DataStructures/ImportNode.h" #include "../Util/SimpleLogger.h" #include -#include -#include -#include - #include #include ExtractorCallbacks::ExtractorCallbacks() : - stringMap(NULL), + string_map(NULL), externalMemory(NULL) { } ExtractorCallbacks::ExtractorCallbacks( ExtractionContainers * ext, - StringMap * strMap + boost::unordered_map * string_map ) : - stringMap(strMap), + string_map(string_map), externalMemory(ext) { } @@ -93,11 +89,11 @@ void ExtractorCallbacks::wayFunction(ExtractionWay &parsed_way) { } //Get the unique identifier for the street name - const StringMap::const_iterator & string_map_iterator = stringMap->find(parsed_way.name); - if(stringMap->end() == string_map_iterator) { + const boost::unordered_map::const_iterator & string_map_iterator = string_map->find(parsed_way.name); + if(string_map->end() == string_map_iterator) { parsed_way.nameID = externalMemory->name_list.size(); externalMemory->name_list.push_back(parsed_way.name); - stringMap->insert(std::make_pair(parsed_way.name, parsed_way.nameID)); + string_map->insert(std::make_pair(parsed_way.name, parsed_way.nameID)); } else { parsed_way.nameID = string_map_iterator->second; } diff --git a/Extractor/ExtractorCallbacks.h b/Extractor/ExtractorCallbacks.h index 555d19a12..3a27b6ed8 100644 --- a/Extractor/ExtractorCallbacks.h +++ b/Extractor/ExtractorCallbacks.h @@ -28,29 +28,27 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef EXTRACTORCALLBACKS_H_ #define EXTRACTORCALLBACKS_H_ -#include "ExtractorStructs.h" #include "../typedefs.h" #include #include +struct ExternalMemoryNode; class ExtractionContainers; struct ExtractionWay; struct InputRestrictionContainer; -typedef boost::unordered_map StringMap; - class ExtractorCallbacks{ private: - StringMap * stringMap; + boost::unordered_map * string_map; ExtractionContainers * externalMemory; ExtractorCallbacks(); public: explicit ExtractorCallbacks( ExtractionContainers * ext, - StringMap * strMap + boost::unordered_map * string_map ); ~ExtractorCallbacks(); diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index f229ae103..003552885 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ScriptingEnvironment.h" #include "../DataStructures/HashTable.h" +#include "../DataStructures/ImportNode.h" #include "../DataStructures/Restriction.h" #include "../Util/MachineInfo.h" #include "../Util/OpenMPWrapper.h" diff --git a/Extractor/PBFParser.h b/Extractor/PBFParser.h index 91c89157b..e67a845b8 100644 --- a/Extractor/PBFParser.h +++ b/Extractor/PBFParser.h @@ -76,13 +76,13 @@ public: private: inline void ReadData(); inline void ParseData(); - inline void parseDenseNode (_ThreadData * threadData); - inline void parseNode (_ThreadData * threadData); - inline void parseRelation (_ThreadData * threadData); - inline void parseWay (_ThreadData * threadData); + inline void parseDenseNode (_ThreadData * threadData); + inline void parseNode (_ThreadData * threadData); + inline void parseRelation (_ThreadData * threadData); + inline void parseWay (_ThreadData * threadData); - inline void loadGroup (_ThreadData * threadData); - inline void loadBlock (_ThreadData * threadData); + inline void loadGroup (_ThreadData * threadData); + inline void loadBlock (_ThreadData * threadData); inline bool readPBFBlobHeader(std::fstream & stream, _ThreadData * threadData); inline bool unpackZLIB (std::fstream & stream, _ThreadData * threadData); inline bool unpackLZMA (std::fstream & stream, _ThreadData * threadData); diff --git a/Extractor/XMLParser.cpp b/Extractor/XMLParser.cpp index 26c31ebd2..2fdcb6a6e 100644 --- a/Extractor/XMLParser.cpp +++ b/Extractor/XMLParser.cpp @@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "XMLParser.h" #include "ExtractionWay.h" +#include "ExtractorCallbacks.h" + #include "../DataStructures/HashTable.h" #include "../DataStructures/ImportNode.h" #include "../DataStructures/InputReaderFactory.h" diff --git a/Extractor/XMLParser.h b/Extractor/XMLParser.h index 9e307fcc1..7c88d48a7 100644 --- a/Extractor/XMLParser.h +++ b/Extractor/XMLParser.h @@ -33,13 +33,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include - class XMLParser : public BaseParser { public: XMLParser( const char* filename, - ExtractorCallbacks* ec, - ScriptingEnvironment& se + ExtractorCallbacks * ec, + ScriptingEnvironment & se ); bool ReadHeader(); bool Parse(); From 024b78da7cc26e448aa023e16e7ce2f8aa589267 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 18:08:08 +0100 Subject: [PATCH 24/89] Forward decl to cut compile times --- extractor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extractor.cpp b/extractor.cpp index 70ff15ced..041635ee8 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -43,6 +43,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + #include #include #include @@ -180,7 +182,7 @@ int main (int argc, char *argv[]) { } } - StringMap stringMap; + boost::unordered_map stringMap; ExtractionContainers externalMemory; stringMap[""] = 0; From 9b33aaa11a13f0bb8c82a317a5774003b548af80 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 18:09:20 +0100 Subject: [PATCH 25/89] fix test for borked lat/lons --- Server/DataStructures/InternalDataFacade.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 7e0177c68..8a9c1bb20 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -147,8 +147,8 @@ private: 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 ); + BOOST_ASSERT( ( std::abs(m_coordinate_list->at(i).lat) >> 30) == 0 ); + BOOST_ASSERT( ( std::abs(m_coordinate_list->at(i).lon) >> 30) == 0 ); } nodes_input_stream.close(); From 0dbe5e65937ff5b1265b1c0aa4817957887d13b6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 18:09:54 +0100 Subject: [PATCH 26/89] fix shortest ch query for certain cases --- RoutingAlgorithms/AlternativePathRouting.h | 90 ++++++++++++++++------ RoutingAlgorithms/BasicRoutingInterface.h | 7 +- RoutingAlgorithms/ShortestPathRouting.h | 8 +- 3 files changed, 76 insertions(+), 29 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index d04c4b4f9..8162b8e8e 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -96,7 +96,6 @@ public: std::vector forward_search_space; std::vector reverse_search_space; - //Init queues, semi-expensive because access to TSS invokes a sys-call engine_working_data.InitializeOrClearFirstThreadLocalStorage( super::facade->GetNumberOfNodes() @@ -114,7 +113,7 @@ public: QueryHeap & reverse_heap2 = *(engine_working_data.backwardHeap2); int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT; - NodeID middle_node = UINT_MAX; + NodeID middle_node = SPECIAL_NODEID; if(phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID ) { SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id; forward_heap1.Insert( @@ -183,7 +182,8 @@ public: ); } } - sort_unique_resize(via_node_candidate_list); + SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; + sort_unique_resize( via_node_candidate_list ); SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; std::vector packed_forward_path; @@ -340,7 +340,7 @@ public: SimpleLogger().Write(logDEBUG) << "upper_bound_to_shortest_path_distance: " << upper_bound_to_shortest_path_distance; } - if(SPECIAL_NODEID != selected_via_node ) { + if( SPECIAL_NODEID != selected_via_node ) { std::vector packed_alternate_path; // retrieve alternate path RetrievePackedAlternatePath( @@ -481,37 +481,68 @@ private: i < s_v_min_path_size; ++i ) { - if(packed_s_v_path[i] == packed_shortest_path[i] && packed_s_v_path[i + 1] == packed_shortest_path[i + 1]) { + if( packed_s_v_path[i] == packed_shortest_path[i] && + packed_s_v_path[i+1] == packed_shortest_path[i+1] + ) { 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], partially_unpacked_via_path); - super::UnpackEdge(packed_shortest_path[i], packed_shortest_path[i+1], partially_unpacked_shortest_path); + super::UnpackEdge( + packed_s_v_path[i], + packed_s_v_path[i+1], + partially_unpacked_via_path + ); + super::UnpackEdge( + packed_shortest_path[i], + packed_shortest_path[i+1], + partially_unpacked_shortest_path + ); break; } } } //traverse partially unpacked edge and note common prefix - for (int i = 0, packed_path_length = std::min( partially_unpacked_via_path.size(), partially_unpacked_shortest_path.size()) - 1; (i < packed_path_length) && (partially_unpacked_via_path[i] == partially_unpacked_shortest_path[i] && partially_unpacked_via_path[i+1] == partially_unpacked_shortest_path[i+1]); ++i) { - EdgeID edgeID = facade->FindEdgeInEitherDirection(partially_unpacked_via_path[i], partially_unpacked_via_path[i+1]); + for( + int i = 0, packed_path_length = std::min( partially_unpacked_via_path.size(), partially_unpacked_shortest_path.size()) - 1; + (i < packed_path_length) && (partially_unpacked_via_path[i] == partially_unpacked_shortest_path[i] && partially_unpacked_via_path[i+1] == partially_unpacked_shortest_path[i+1]); + ++i + ) { + EdgeID edgeID = facade->FindEdgeInEitherDirection( + partially_unpacked_via_path[i], + partially_unpacked_via_path[i+1] + ); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } //Second, partially unpack v-->t in reverse order until paths deviate and note lengths - int via_path_index = packed_v_t_path.size() - 1; - int shortest_path_index = packed_shortest_path.size() - 1; - for (; + int via_path_index = packed_v_t_path.size()-1; + int shortest_path_index = packed_shortest_path.size()-1; + for(; via_path_index > 0 && shortest_path_index > 0; --via_path_index,--shortest_path_index ) { - if (packed_v_t_path[via_path_index-1] == packed_shortest_path[shortest_path_index-1] && packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) { - EdgeID edgeID = facade->FindEdgeInEitherDirection( packed_v_t_path[via_path_index-1], packed_v_t_path[via_path_index]); + if( + packed_v_t_path[via_path_index-1] == packed_shortest_path[shortest_path_index-1] && + packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index] + ) { + EdgeID edgeID = facade->FindEdgeInEitherDirection( + packed_v_t_path[via_path_index-1], + packed_v_t_path[via_path_index] + ); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { - if (packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index]) { - super::UnpackEdge(packed_v_t_path[via_path_index-1], packed_v_t_path[via_path_index], partially_unpacked_via_path); - super::UnpackEdge(packed_shortest_path[shortest_path_index-1] , packed_shortest_path[shortest_path_index], partially_unpacked_shortest_path); + if( packed_v_t_path[via_path_index] == packed_shortest_path[shortest_path_index] ) { + super::UnpackEdge( + packed_v_t_path[via_path_index-1], + packed_v_t_path[via_path_index], + partially_unpacked_via_path + ); + super::UnpackEdge( + packed_shortest_path[shortest_path_index-1], + packed_shortest_path[shortest_path_index], + partially_unpacked_shortest_path + ); break; } } @@ -519,9 +550,18 @@ private: via_path_index = partially_unpacked_via_path.size()-1; shortest_path_index = partially_unpacked_shortest_path.size()-1; - for (; via_path_index > 0 && shortest_path_index > 0; --via_path_index,--shortest_path_index) { - if (partially_unpacked_via_path[via_path_index-1] == partially_unpacked_shortest_path[shortest_path_index-1] && partially_unpacked_via_path[via_path_index] == partially_unpacked_shortest_path[shortest_path_index]) { - EdgeID edgeID = facade->FindEdgeInEitherDirection( partially_unpacked_via_path[via_path_index-1], partially_unpacked_via_path[via_path_index]); + for(; + via_path_index > 0 && shortest_path_index > 0; + --via_path_index,--shortest_path_index + ) { + if( + partially_unpacked_via_path[via_path_index-1] == partially_unpacked_shortest_path[shortest_path_index-1] && + partially_unpacked_via_path[via_path_index] == partially_unpacked_shortest_path[shortest_path_index] + ) { + EdgeID edgeID = facade->FindEdgeInEitherDirection( + partially_unpacked_via_path[via_path_index-1], + partially_unpacked_via_path[via_path_index] + ); *sharing_of_via_path += facade->GetEdgeData(edgeID).distance; } else { break; @@ -619,12 +659,12 @@ private: const int to_distance = distance + edge_weight; //New Node discovered -> Add to Heap + Node Info Storage - if ( !forward_heap.WasInserted( to ) ) { + if( !forward_heap.WasInserted( to ) ) { forward_heap.Insert( to, to_distance, node ); } //Found a shorter Path -> Update distance - else if ( to_distance < forward_heap.GetKey( to ) ) { + else if( to_distance < forward_heap.GetKey( to ) ) { // new parent forward_heap.GetData( to ).parent = node; // decreased distance @@ -726,7 +766,11 @@ private: while( !unpack_stack.empty() ) { const SearchSpaceEdge via_path_edge = unpack_stack.top(); unpack_stack.pop(); - EdgeID edge_in_via_path_id = facade->FindEdgeInEitherDirection(via_path_edge.first, via_path_edge.second); + EdgeID edge_in_via_path_id = facade->FindEdgeInEitherDirection( + via_path_edge.first, + via_path_edge.second + ); + if( SPECIAL_EDGEID == edge_in_via_path_id ) { return false; } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index dd2798b44..ba5d60926 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -256,7 +256,9 @@ public: } if(SPECIAL_EDGEID != packed_geometry_id_of_last_edge) { SimpleLogger().Write(logDEBUG) << "unpacking last segment " << packed_geometry_id_of_last_edge; + SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << (start_traversed_in_reverse ? "y" : "n"); SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); + SimpleLogger().Write(logDEBUG) << "fwd_index_offset: " << fwd_index_offset << ", rev_index_offset: " << rev_index_offset; std::vector id_vector; facade->GetUncompressedGeometry(packed_geometry_id_of_last_edge, id_vector); if( target_traversed_in_reverse ) { @@ -264,17 +266,18 @@ public: } SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); const bool start_and_end_on_same_edge = (packed_geometry_id_of_first_edge == packed_geometry_id_of_last_edge) && unpacked_path.empty(); + const int start_index = ( start_and_end_on_same_edge ? id_vector.size() - fwd_index_offset : 0 ); const int end_index = (target_traversed_in_reverse ? id_vector.size() - rev_index_offset : rev_index_offset); SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; BOOST_ASSERT( start_index >= 0 ); - BOOST_ASSERT( start_index <= end_index ); + // BOOST_ASSERT( start_index <= end_index ); for( unsigned i = start_index; i < end_index; - ++i + ( start_index < end_index ? ++i :--i) ) { SimpleLogger().Write(logDEBUG) << facade->GetCoordinateOfNode(id_vector[i]); unpacked_path.push_back( diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 6ff786a33..f7719db9b 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -161,7 +161,7 @@ public: //run two-Target Dijkstra routing step. while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){ - if( !forward_heap1.Empty()){ + if( 0 < forward_heap1.Size() ){ super::RoutingStep( forward_heap1, reverse_heap1, @@ -171,7 +171,7 @@ public: true ); } - if( !reverse_heap1.Empty() ){ + if( 0 < reverse_heap1.Size() ){ super::RoutingStep( reverse_heap1, forward_heap1, @@ -185,7 +185,7 @@ public: if( !reverse_heap2.Empty() ) { while(0 < (forward_heap2.Size() + reverse_heap2.Size() )){ - if( !forward_heap2.Empty() ){ + if( 0 < forward_heap2.Size() ){ super::RoutingStep( forward_heap2, reverse_heap2, @@ -195,7 +195,7 @@ public: true ); } - if( !reverse_heap2.Empty() ){ + if( 0 < reverse_heap2.Size() ){ super::RoutingStep( reverse_heap2, forward_heap2, From bc0665cd9f34fcdaa68e67cd555496f2d13dd21a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 6 Mar 2014 19:23:56 +0100 Subject: [PATCH 27/89] fix offsets for start and end --- DataStructures/PhantomNodes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 46331ea62..b299e5fad 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -59,11 +59,11 @@ struct PhantomNode { int GetForwardWeightPlusOffset() const { - return forward_weight + forward_offset; + return forward_weight - forward_offset; } int GetReverseWeightPlusOffset() const { - return reverse_weight - reverse_offset; + return reverse_weight + reverse_offset; } void Reset() { From b60cfd92942388f0d034fdfb6548f76f09109cb6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 10 Mar 2014 15:36:58 +0100 Subject: [PATCH 28/89] last segment gets it proper name now --- RoutingAlgorithms/AlternativePathRouting.h | 66 ++++++++++++---------- RoutingAlgorithms/BasicRoutingInterface.h | 31 +++++----- RoutingAlgorithms/ShortestPathRouting.h | 33 +++++------ 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 8162b8e8e..e9ba6fee7 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -38,9 +38,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -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. +const double VIAPATH_ALPHA = 0.10; +const double VIAPATH_EPSILON = 0.15; // alternative at most 15% longer +const double VIAPATH_GAMMA = 0.75; // alternative shares at most 75% with the shortest. template class AlternativeRouting : private BasicRoutingInterface { @@ -50,10 +50,14 @@ class AlternativeRouting : private BasicRoutingInterface { 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 node, + const int length, + const int sharing + ) : + node(node), + length(length), + sharing(sharing) { } NodeID node; @@ -255,7 +259,7 @@ public: const int approximated_length = forward_heap1.GetKey(node) + reverse_heap1.GetKey(node); const bool length_passes = (approximated_length < upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)); const bool sharing_passes = (approximated_sharing <= upper_bound_to_shortest_path_distance*VIAPATH_GAMMA); - const bool stretch_passes = (approximated_length - approximated_sharing) < ((1.+VIAPATH_EPSILON)*(upper_bound_to_shortest_path_distance-approximated_sharing)); + const bool stretch_passes = (approximated_length - approximated_sharing) < ((1.+VIAPATH_ALPHA)*(upper_bound_to_shortest_path_distance-approximated_sharing)); if( length_passes && sharing_passes && stretch_passes ) { preselected_node_list.push_back(node); @@ -279,7 +283,7 @@ public: int length_of_via_path = 0, sharing_of_via_path = 0; ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path, forward_offset+reverse_offset, packed_shortest_path); const int maximum_allowed_sharing = upper_bound_to_shortest_path_distance*VIAPATH_GAMMA; - if( sharing_of_via_path <= maximum_allowed_sharing ) { + if( sharing_of_via_path <= maximum_allowed_sharing && length_of_via_path <= upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)) { ranked_candidates_list.push_back( RankedCandidateNode( node, @@ -317,22 +321,16 @@ public: // int start_offset = ( packed_shortest_path.front() == phantom_node_pair.startPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.startPhantom.fwd_segment_position; // SimpleLogger().Write(logDEBUG) << "unpacking from index " << phantom_node_pair.startPhantom.fwd_segment_position; - SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.forward_node_id: " << phantom_node_pair.startPhantom.forward_node_id; - SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.reverse_node_id: " << phantom_node_pair.startPhantom.reverse_node_id; - SimpleLogger().Write(logDEBUG) << "phantom_node_pair.targetPhantom.packed_geometry_id: " << phantom_node_pair.targetPhantom.packed_geometry_id; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.forward_node_id: " << phantom_node_pair.startPhantom.forward_node_id; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.reverse_node_id: " << phantom_node_pair.startPhantom.reverse_node_id; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.targetPhantom.packed_geometry_id: " << phantom_node_pair.targetPhantom.packed_geometry_id; // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); super::UnpackPath( // -- packed input packed_shortest_path, // -- start of route - phantom_node_pair.startPhantom.packed_geometry_id, - phantom_node_pair.startPhantom.fwd_segment_position, - (packed_shortest_path.front() != phantom_node_pair.startPhantom.forward_node_id), - // -- end of route - phantom_node_pair.targetPhantom.packed_geometry_id, - phantom_node_pair.targetPhantom.fwd_segment_position, - (packed_shortest_path.back() != phantom_node_pair.targetPhantom.forward_node_id), + phantom_node_pair, // -- unpacked output raw_route_data.unpacked_path_segments.front() ); @@ -356,12 +354,7 @@ public: // unpack the alternate path super::UnpackPath( packed_alternate_path, - phantom_node_pair.startPhantom.packed_geometry_id, - phantom_node_pair.startPhantom.fwd_segment_position, - (packed_alternate_path.front() != phantom_node_pair.startPhantom.forward_node_id), - phantom_node_pair.targetPhantom.packed_geometry_id, - phantom_node_pair.targetPhantom.fwd_segment_position, - (packed_alternate_path.back() != phantom_node_pair.targetPhantom.forward_node_id), + phantom_node_pair, raw_route_data.unpacked_alternative ); @@ -406,10 +399,17 @@ private: ); } - inline void ComputeLengthAndSharingOfViaPath(const NodeID via_node, int *real_length_of_via_path, int *sharing_of_via_path, - 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 + //TODO: reorder parameters + // compute and unpack and by exploring search spaces + // from v and intersecting against queues. only half-searches have to be + // done at this stage + inline void ComputeLengthAndSharingOfViaPath( + const NodeID via_node, + int *real_length_of_via_path, + int *sharing_of_via_path, + const int offset, + const std::vector & packed_shortest_path + ) { engine_working_data.InitializeOrClearSecondThreadLocalStorage( super::facade->GetNumberOfNodes() ); @@ -609,6 +609,7 @@ private: // return sharing; // } + //todo: reorder parameters template inline void AlternativeRoutingStep( QueryHeap & forward_heap, @@ -622,7 +623,12 @@ private: const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); const int scaled_distance = (distance-edge_expansion_offset)/(1.+VIAPATH_EPSILON); - if( scaled_distance > *upper_bound_to_shortest_path_distance ){ + // SimpleLogger().Write(logDEBUG) << "ub: " << *upper_bound_to_shortest_path_distance << ", distance: " << distance << ", scaled_distance: " << scaled_distance; + if( + (INVALID_EDGE_WEIGHT != *upper_bound_to_shortest_path_distance) && + (scaled_distance > *upper_bound_to_shortest_path_distance) + ) { + // SimpleLogger().Write(logDEBUG) << "removing nodes from heap"; forward_heap.DeleteAll(); return; } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index ba5d60926..63bcd1ac3 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -38,8 +38,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include - #include SearchEngineData::SearchEngineHeapPtr SearchEngineData::forwardHeap; @@ -140,14 +138,12 @@ public: //TODO: refactor parameters to only edge ids for start and end inline void UnpackPath( const std::vector & packed_path, - const unsigned packed_geometry_id_of_first_edge, - const int fwd_index_offset, - const bool start_traversed_in_reverse, - const unsigned packed_geometry_id_of_last_edge, - const int rev_index_offset, - const bool target_traversed_in_reverse, + const PhantomNodes & phantom_node_pair, std::vector & unpacked_path ) const { + const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.startPhantom.forward_node_id); + const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.targetPhantom.forward_node_id); + const unsigned packed_path_size = packed_path.size(); std::stack > recursion_stack; @@ -230,7 +226,7 @@ public: std::vector id_vector; facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id), id_vector); - const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - fwd_index_offset - 1 : fwd_index_offset ) : 0 ); + const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1 : phantom_node_pair.startPhantom.fwd_segment_position ) : 0 ); const int end_index = id_vector.size(); BOOST_ASSERT( start_index >= 0 ); @@ -254,21 +250,22 @@ public: } } } - if(SPECIAL_EDGEID != packed_geometry_id_of_last_edge) { - SimpleLogger().Write(logDEBUG) << "unpacking last segment " << packed_geometry_id_of_last_edge; + if(SPECIAL_EDGEID != phantom_node_pair.targetPhantom.packed_geometry_id ) { + SimpleLogger().Write(logDEBUG) << "unpacking last segment " << phantom_node_pair.targetPhantom.packed_geometry_id; SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << (start_traversed_in_reverse ? "y" : "n"); SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); - SimpleLogger().Write(logDEBUG) << "fwd_index_offset: " << fwd_index_offset << ", rev_index_offset: " << rev_index_offset; + SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.fwd_segment_position: " << phantom_node_pair.startPhantom.fwd_segment_position << ", " << + "phantom_node_pair.targetPhantom.fwd_segment_position: " << phantom_node_pair.targetPhantom.fwd_segment_position; std::vector id_vector; - facade->GetUncompressedGeometry(packed_geometry_id_of_last_edge, id_vector); + facade->GetUncompressedGeometry(phantom_node_pair.targetPhantom.packed_geometry_id, id_vector); if( target_traversed_in_reverse ) { std::reverse(id_vector.begin(), id_vector.end() ); } SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); - const bool start_and_end_on_same_edge = (packed_geometry_id_of_first_edge == packed_geometry_id_of_last_edge) && unpacked_path.empty(); + const bool start_and_end_on_same_edge = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty(); - const int start_index = ( start_and_end_on_same_edge ? id_vector.size() - fwd_index_offset : 0 ); - const int end_index = (target_traversed_in_reverse ? id_vector.size() - rev_index_offset : rev_index_offset); + const int start_index = ( start_and_end_on_same_edge ? phantom_node_pair.startPhantom.fwd_segment_position : 0 ); + const int end_index = (target_traversed_in_reverse ? id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position : phantom_node_pair.targetPhantom.fwd_segment_position); SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; @@ -283,7 +280,7 @@ public: unpacked_path.push_back( PathData( id_vector[i], - 0, + phantom_node_pair.targetPhantom.name_id, TurnInstructionsClass::NoTurn, 0 ) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index f7719db9b..6225aa644 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -359,7 +359,7 @@ public: std::swap( packed_legs1, packed_legs2 ); } raw_route_data.unpacked_path_segments.resize( packed_legs1.size() ); - const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().startPhantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().startPhantom.fwd_segment_position; + // const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().startPhantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().startPhantom.fwd_segment_position; for(unsigned i = 0; i < packed_legs1.size(); ++i){ BOOST_ASSERT( !phantom_nodes_vector.empty() ); @@ -367,30 +367,27 @@ public: const bool at_end = (packed_legs1.size() == i+1); BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); + PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i]; + if (!at_beginning) + { + unpack_phantom_node_pair.startPhantom.packed_geometry_id = SPECIAL_EDGEID; + unpack_phantom_node_pair.startPhantom.fwd_segment_position = 0; + } + + if (!at_end) + { + unpack_phantom_node_pair.targetPhantom.packed_geometry_id = SPECIAL_EDGEID; + unpack_phantom_node_pair.targetPhantom.fwd_segment_position = 0; + } super::UnpackPath( // -- packed input packed_legs1[i], - // -- start of route - ( !at_beginning ? SPECIAL_EDGEID : phantom_nodes_vector.front().startPhantom.packed_geometry_id ), - ( !at_beginning ? 0 : phantom_nodes_vector.front().startPhantom.fwd_segment_position ), - ( !at_beginning ? false : (packed_legs1.front().front() != phantom_nodes_vector.front().startPhantom.forward_node_id) ), - // -- end of route - ( !at_end ? SPECIAL_EDGEID : phantom_nodes_vector.back().targetPhantom.packed_geometry_id ), - ( !at_end ? 0 : phantom_nodes_vector.back().targetPhantom.fwd_segment_position ), - ( !at_end ? false : (packed_legs1.back().back() != phantom_nodes_vector.back().targetPhantom.forward_node_id) ), + // -- start and end of (sub-)route + unpack_phantom_node_pair, // -- unpacked output raw_route_data.unpacked_path_segments[i] ); - - - // // TODO: properly unpack first and last segments - // super::UnpackPath( - // packed_legs1[i], - // SPECIAL_EDGEID, ( at_beginning ? start_offset : 0), false, - // SPECIAL_EDGEID, 0, false, - // raw_route_data.unpacked_path_segments[i] - // ); } raw_route_data.lengthOfShortestPath = std::min(distance1, distance2); } From ba37836e2479c866365e73b12ccb99922f7029d1 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 10 Mar 2014 15:37:17 +0100 Subject: [PATCH 29/89] allow graphs with zero edges to load --- Server/DataStructures/InternalDataFacade.h | 2 +- Util/GraphLoader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 8a9c1bb20..11f26734d 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -115,7 +115,7 @@ private: ); BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty"); - BOOST_ASSERT_MSG(0 != edge_list.size(), "edge 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); diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 37174b3b2..ce0a17ca4 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -446,7 +446,7 @@ unsigned readHSGRFromStream( 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"); + // 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]), From fdebec6448f0472e7ac4bb274d5153138287cd51 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 12 Mar 2014 17:23:21 +0100 Subject: [PATCH 30/89] correct partial distances --- DataStructures/Coordinate.cpp | 7 ++- DataStructures/PhantomNodes.h | 6 +-- DataStructures/StaticRTree.h | 16 +++++-- RoutingAlgorithms/AlternativePathRouting.h | 15 ++++-- RoutingAlgorithms/BasicRoutingInterface.h | 53 +++++++++++++++++++--- RoutingAlgorithms/ShortestPathRouting.h | 38 +++++++++------- 6 files changed, 100 insertions(+), 35 deletions(-) diff --git a/DataStructures/Coordinate.cpp b/DataStructures/Coordinate.cpp index dc90b20e0..3fb2cfc04 100644 --- a/DataStructures/Coordinate.cpp +++ b/DataStructures/Coordinate.cpp @@ -31,7 +31,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#ifndef NDEBUG #include +#endif #include #include @@ -44,6 +46,7 @@ FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon) { +#ifndef NDEBUG if(0 != (std::abs(lat) >> 30)) { std::bitset<32> y(lat); SimpleLogger().Write(logDEBUG) << "broken lat: " << lat << ", bits: " << y; @@ -52,6 +55,7 @@ FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) std::bitset<32> x(lon); SimpleLogger().Write(logDEBUG) << "broken lon: " << lon << ", bits: " << x; } +#endif } void FixedPointCoordinate::Reset() { @@ -59,7 +63,8 @@ void FixedPointCoordinate::Reset() { lon = std::numeric_limits::min(); } bool FixedPointCoordinate::isSet() const { - return (std::numeric_limits::min() != lat) && (std::numeric_limits::min() != lon); + return (std::numeric_limits::min() != lat) && + (std::numeric_limits::min() != lon); } bool FixedPointCoordinate::isValid() const { if( diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index b299e5fad..a6af5a189 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -59,11 +59,11 @@ struct PhantomNode { int GetForwardWeightPlusOffset() const { - return forward_weight - forward_offset; + return forward_weight + forward_offset; } int GetReverseWeightPlusOffset() const { - return reverse_weight + reverse_offset; + return reverse_offset + reverse_weight; } void Reset() { @@ -123,7 +123,7 @@ struct PhantomNodes { //TODO: Rename to: BothPhantomNodesAreInvalid bool AtLeastOnePhantomNodeIsUINTMAX() const { - return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.forward_node_id == SPECIAL_NODEID); + return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.reverse_node_id == SPECIAL_NODEID); } bool PhantomNodesHaveEqualLocation() const { diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index fbd96b23f..a571bf083 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -758,15 +758,25 @@ public: ratio = std::min(1., ratio); } - result_phantom_node.forward_weight *= ratio; - if( INT_MAX != result_phantom_node.reverse_weight ) { - result_phantom_node.reverse_weight *= (1.-ratio); + SimpleLogger().Write(logDEBUG) << "result_phantom_node.forward_offset: " << result_phantom_node.forward_offset; + SimpleLogger().Write(logDEBUG) << "result_phantom_node.reverse_offset: " << result_phantom_node.reverse_offset; + SimpleLogger().Write(logDEBUG) << "result_phantom_node.forward_weight: " << result_phantom_node.forward_weight; + SimpleLogger().Write(logDEBUG) << "result_phantom_node.reverse_weight: " << result_phantom_node.reverse_weight; + + if (SPECIAL_NODEID != result_phantom_node.forward_node_id) + { + result_phantom_node.forward_weight *= (1.-ratio); + } + if( SPECIAL_NODEID != result_phantom_node.reverse_node_id ) + { + result_phantom_node.reverse_weight *= ratio; } result_phantom_node.ratio = ratio; SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight << ", ratio: " << result_phantom_node.ratio; + SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset << ", ratio: " << result_phantom_node.ratio; SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id; SimpleLogger().Write(logDEBUG) << "geom id: " << result_phantom_node.packed_geometry_id; diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index e9ba6fee7..02b1bfca1 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -119,7 +119,7 @@ public: int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT; NodeID middle_node = SPECIAL_NODEID; if(phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id; + SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.startPhantom.forward_node_id, -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), @@ -127,7 +127,7 @@ public: ); } if(phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.reverse_node_id; + SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), @@ -136,7 +136,7 @@ public: } if(phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id; + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id << ", w: " << phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.targetPhantom.forward_node_id, phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), @@ -144,7 +144,7 @@ public: ); } if(phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id; + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id << ", w: " << phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.targetPhantom.reverse_node_id, phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), @@ -186,6 +186,7 @@ public: ); } } + SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; sort_unique_resize( via_node_candidate_list ); SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; @@ -204,6 +205,10 @@ public: packed_reverse_path ); + //TODO: leave early when no path found: + + SimpleLogger().Write(logDEBUG) << "ub: " << upper_bound_to_shortest_path_distance; + boost::unordered_map approximated_forward_sharing; boost::unordered_map approximated_reverse_sharing; @@ -623,7 +628,7 @@ private: const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); const int scaled_distance = (distance-edge_expansion_offset)/(1.+VIAPATH_EPSILON); - // SimpleLogger().Write(logDEBUG) << "ub: " << *upper_bound_to_shortest_path_distance << ", distance: " << distance << ", scaled_distance: " << scaled_distance; + SimpleLogger().Write(logDEBUG) << "node: " << node << ", distance: " << distance << ", ub: " << *upper_bound_to_shortest_path_distance << ", scaled_distance: " << scaled_distance; if( (INVALID_EDGE_WEIGHT != *upper_bound_to_shortest_path_distance) && (scaled_distance > *upper_bound_to_shortest_path_distance) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 63bcd1ac3..3bd3dd04b 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -141,6 +141,7 @@ public: const PhantomNodes & phantom_node_pair, std::vector & unpacked_path ) const { + SimpleLogger().Write(logDEBUG) << "packed_path.size: " << packed_path.size(); const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.startPhantom.forward_node_id); const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.targetPhantom.forward_node_id); @@ -262,10 +263,38 @@ public: std::reverse(id_vector.begin(), id_vector.end() ); } SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); - const bool start_and_end_on_same_edge = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty(); + SimpleLogger().Write(logDEBUG) << "unpacked_path.empty()=" << (unpacked_path.empty() ? "y" : "n"); - const int start_index = ( start_and_end_on_same_edge ? phantom_node_pair.startPhantom.fwd_segment_position : 0 ); - const int end_index = (target_traversed_in_reverse ? id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position : phantom_node_pair.targetPhantom.fwd_segment_position); + const bool is_local_path = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty(); + SimpleLogger().Write(logDEBUG) << "is_local_path: " << (is_local_path ? "y" : "n"); + + + // const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1 : phantom_node_pair.startPhantom.fwd_segment_position ) : 0 ); + + int start_index = 0; + int end_index = phantom_node_pair.targetPhantom.fwd_segment_position; + SimpleLogger().Write(logDEBUG) << "case1"; + if (target_traversed_in_reverse) + { + // start_index = id_vector.size() -1; + end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position; + // if (is_local_path) + // { + // start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position -1; + // } + } + if (is_local_path) + { + SimpleLogger().Write(logDEBUG) << "case3"; + start_index = phantom_node_pair.startPhantom.fwd_segment_position - 1; + end_index = phantom_node_pair.targetPhantom.fwd_segment_position - 1; + if (target_traversed_in_reverse) + { + SimpleLogger().Write(logDEBUG) << "case4"; + start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1; + end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position - 1; + } + } SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; @@ -273,10 +302,10 @@ public: // BOOST_ASSERT( start_index <= end_index ); for( unsigned i = start_index; - i < end_index; + i != end_index; ( start_index < end_index ? ++i :--i) ) { - SimpleLogger().Write(logDEBUG) << facade->GetCoordinateOfNode(id_vector[i]); + SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); unpacked_path.push_back( PathData( id_vector[i], @@ -391,8 +420,18 @@ public: } } - int ComputeEdgeOffset(const PhantomNode & phantom) const { - return phantom.forward_weight + (phantom.isBidirected() ? phantom.reverse_weight : 0); + int ComputeEdgeOffset(const PhantomNode & phantom_node) const { + int weight_offset = 0; + if (phantom_node.forward_node_id != SPECIAL_NODEID) + { + weight_offset += phantom_node.GetForwardWeightPlusOffset(); + } + if (phantom_node.reverse_node_id != SPECIAL_NODEID) + { + weight_offset += phantom_node.GetReverseWeightPlusOffset(); + } + return weight_offset; + // return phantom_node.forward_weight + (phantom_node.isBidirected() ? phantom_node.reverse_weight : 0); } }; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 6225aa644..6c2e40203 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -63,6 +63,8 @@ public: if( phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() ) { // raw_route_data.lengthOfShortestPath = INT_MAX; // raw_route_data.lengthOfAlternativePath = INT_MAX; + SimpleLogger().Write(logDEBUG) << "returning early"; + return; } } @@ -108,14 +110,15 @@ public: search_from_1st_node && phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.startPhantom.forward_node_id, - distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), + -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.GetForwardWeightPlusOffset(), + -distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.startPhantom.forward_node_id ); } @@ -123,20 +126,22 @@ public: search_from_2nd_node && phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, - distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), + -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.GetReverseWeightPlusOffset(), + -distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.startPhantom.reverse_node_id ); } //insert new backward nodes into backward heap, unadjusted. if( phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id << ", w: " << phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.targetPhantom.forward_node_id, phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), @@ -145,6 +150,7 @@ public: } if( phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id << ", w: " << phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(); reverse_heap2.Insert( phantom_node_pair.targetPhantom.reverse_node_id, phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), @@ -363,22 +369,22 @@ public: for(unsigned i = 0; i < packed_legs1.size(); ++i){ BOOST_ASSERT( !phantom_nodes_vector.empty() ); - const bool at_beginning = (0 == i); - const bool at_end = (packed_legs1.size() == i+1); + const bool at_beginning = (packed_legs1[i] == packed_legs1.front()); + const bool at_end = (packed_legs1[i] == packed_legs1.back()); BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i]; - if (!at_beginning) - { - unpack_phantom_node_pair.startPhantom.packed_geometry_id = SPECIAL_EDGEID; - unpack_phantom_node_pair.startPhantom.fwd_segment_position = 0; - } + // if (!at_beginning) + // { + // unpack_phantom_node_pair.startPhantom.packed_geometry_id = SPECIAL_EDGEID; + // unpack_phantom_node_pair.startPhantom.fwd_segment_position = 0; + // } - if (!at_end) - { - unpack_phantom_node_pair.targetPhantom.packed_geometry_id = SPECIAL_EDGEID; - unpack_phantom_node_pair.targetPhantom.fwd_segment_position = 0; - } + // if (!at_end) + // { + // unpack_phantom_node_pair.targetPhantom.packed_geometry_id = SPECIAL_EDGEID; + // unpack_phantom_node_pair.targetPhantom.fwd_segment_position = 0; + // } super::UnpackPath( // -- packed input From 87f036e538860467c0a76df8ae5193cf82f41d38 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 19 Mar 2014 16:42:37 +0100 Subject: [PATCH 31/89] fixing sentinel nodes in adjacency list graph data structure --- Contractor/EdgeBasedGraphFactory.cpp | 14 ++- Contractor/EdgeBasedGraphFactory.h | 2 + DataStructures/PhantomNodes.h | 8 +- DataStructures/StaticGraph.h | 18 ++- DataStructures/StaticRTree.h | 4 +- RoutingAlgorithms/AlternativePathRouting.h | 3 +- RoutingAlgorithms/BasicRoutingInterface.h | 21 +++- RoutingAlgorithms/ShortestPathRouting.h | 12 +- Util/GraphLoader.h | 13 +++ prepare.cpp | 121 ++++++++++++++------- 10 files changed, 153 insertions(+), 63 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 40a7c2803..782684b4d 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -48,7 +48,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( ) : speed_profile(speed_profile), m_turn_restrictions_count(0), m_number_of_edge_based_nodes(std::numeric_limits::max()), - m_node_info_list(node_info_list) + m_node_info_list(node_info_list), + max_id(0) { BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { std::pair restriction_source = @@ -384,10 +385,20 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( const unsigned geometry_size = forward_geometry.size(); BOOST_ASSERT( geometry_size > 1 ); NodeID current_edge_start_coordinate_id = u; + + if (forward_data.edgeBasedNodeID != SPECIAL_NODEID) + { + max_id = std::max(forward_data.edgeBasedNodeID, max_id); + } + if (SPECIAL_NODEID != reverse_data.edgeBasedNodeID) + { + max_id = std::max(reverse_data.edgeBasedNodeID, max_id); + } // traverse arrays from start and end respectively for( unsigned i = 0; i < geometry_size; ++i ) { BOOST_ASSERT( current_edge_start_coordinate_id == reverse_geometry[geometry_size-1-i].first ); const NodeID current_edge_target_coordinate_id = forward_geometry[i].first; + BOOST_ASSERT( current_edge_target_coordinate_id != current_edge_start_coordinate_id); // build edges m_edge_based_node_list.push_back( @@ -888,6 +899,7 @@ void EdgeBasedGraphFactory::Run( " skips " << skipped_uturns_counter << " U turns"; SimpleLogger().Write() << " skips " << skipped_barrier_turns_counter << " turns over barriers"; + SimpleLogger().Write(logDEBUG) << "maximum written id: " << max_id; } int EdgeBasedGraphFactory::GetTurnPenalty( diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 875af6edb..c949f1622 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -206,6 +206,8 @@ private: const NodeID v, const NodeID w ); + + unsigned max_id; }; #endif /* EDGEBASEDGRAPHFACTORY_H_ */ diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index a6af5a189..9b7076f08 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define PHANTOMNODES_H_ #include +#include "../Util/SimpleLogger.h" #include "../typedefs.h" struct PhantomNode { @@ -59,11 +60,14 @@ struct PhantomNode { int GetForwardWeightPlusOffset() const { - return forward_weight + forward_offset; + SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight; + return reverse_offset + forward_weight; } int GetReverseWeightPlusOffset() const { - return reverse_offset + reverse_weight; + SimpleLogger().Write(logDEBUG) << "->rev_offset: " << reverse_offset << ", weight: " << reverse_weight; + + return forward_offset + reverse_weight; } void Reset() { diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 41e5e61ec..4665dd102 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -101,6 +101,12 @@ public: _nodes.swap(nodes); _edges.swap(edges); + for(unsigned i = 0; i < _numNodes; ++i) + { + SimpleLogger().Write(logDEBUG) << "edges of " << i << ": [" << BeginEdges(i) << "," << EndEdges(i) << ")"; + } + + #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { @@ -112,7 +118,7 @@ public: if(eid2 == UINT_MAX) { SimpleLogger().Write(logWARNING) << "cannot find first segment of edge (" << - u << "," << data.id << "," << v << ")"; + u << "," << data.id << "," << v << "), eid: " << eid; data.shortcut = false; BOOST_ASSERT(false); @@ -121,7 +127,7 @@ public: if(eid2 == UINT_MAX) { SimpleLogger().Write(logWARNING) << "cannot find second segment of edge (" << - u << "," << data.id << "," << v << ")"; + u << "," << data.id << "," << v << "), eid2: " << eid2; data.shortcut = false; BOOST_ASSERT(false); } @@ -129,6 +135,10 @@ public: } p.printIncrement(); } + for(unsigned i = 0; i < _numNodes; ++i) + { + SimpleLogger().Write(logDEBUG) << "edges of " << i << ": [" << BeginEdges(i) << "," << EndEdges(i) << ")"; + } #endif } @@ -157,11 +167,11 @@ public: } EdgeIterator BeginEdges( const NodeIterator n ) const { - return EdgeIterator( _nodes[n].firstEdge ); + return EdgeIterator( _nodes.at(n).firstEdge ); } EdgeIterator EndEdges( const NodeIterator n ) const { - return EdgeIterator( _nodes[n+1].firstEdge ); + return EdgeIterator( _nodes.at(n+1).firstEdge ); } //searches for a specific edge diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index a571bf083..738564547 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -765,11 +765,11 @@ public: if (SPECIAL_NODEID != result_phantom_node.forward_node_id) { - result_phantom_node.forward_weight *= (1.-ratio); + result_phantom_node.forward_weight *= (ratio); } if( SPECIAL_NODEID != result_phantom_node.reverse_node_id ) { - result_phantom_node.reverse_weight *= ratio; + result_phantom_node.reverse_weight *= 1.-ratio; } result_phantom_node.ratio = ratio; diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 02b1bfca1..cd10e28ba 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -86,6 +86,7 @@ public: const PhantomNodes & phantom_node_pair, RawRouteData & raw_route_data ) { + SimpleLogger().Write(logDEBUG) << "alt path routing"; if( //phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() || phantom_node_pair.PhantomNodesHaveEqualLocation() ) { @@ -628,7 +629,7 @@ private: const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); const int scaled_distance = (distance-edge_expansion_offset)/(1.+VIAPATH_EPSILON); - SimpleLogger().Write(logDEBUG) << "node: " << node << ", distance: " << distance << ", ub: " << *upper_bound_to_shortest_path_distance << ", scaled_distance: " << scaled_distance; + // SimpleLogger().Write(logDEBUG) << "node: " << node << ", distance: " << distance << ", ub: " << *upper_bound_to_shortest_path_distance << ", scaled_distance: " << scaled_distance; if( (INVALID_EDGE_WEIGHT != *upper_bound_to_shortest_path_distance) && (scaled_distance > *upper_bound_to_shortest_path_distance) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 3bd3dd04b..bb9391efe 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -67,9 +67,10 @@ public: ) const { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); - // SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; + SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; if(reverse_heap.WasInserted(node) ){ const int new_distance = reverse_heap.GetKey(node) + distance; + SimpleLogger().Write(logDEBUG) << "new_distance: " << new_distance; if(new_distance < *upper_bound ){ if( new_distance >= 0 ) { *middle_node_id = node; @@ -79,6 +80,7 @@ public: } if( (distance-edge_expansion_offset) > *upper_bound ){ + SimpleLogger().Write() << "found path"; forward_heap.DeleteAll(); return; } @@ -99,12 +101,13 @@ public: if(forward_heap.WasInserted( to )) { if(forward_heap.GetKey( to ) + edge_weight < distance) { + SimpleLogger().Write(logDEBUG) << "stalled"; return; } } } } - + SimpleLogger().Write(logDEBUG) << "done stalling"; for( EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node); edge < end_edge; @@ -122,12 +125,14 @@ public: //New Node discovered -> Add to Heap + Node Info Storage if ( !forward_heap.WasInserted( to ) ) { + SimpleLogger().Write() << "insert (" << node << "," << to << "), distance: " << to_distance << ", edge id: " << edge; forward_heap.Insert( to, to_distance, node ); } //Found a shorter Path -> Update distance else if ( to_distance < forward_heap.GetKey( to ) ) { forward_heap.GetData( to ).parent = node; forward_heap.DecreaseKey( to, to_distance ); + SimpleLogger().Write() << "decrease (" << node << "," << to << "), distance: " << to_distance; //new parent } } @@ -286,8 +291,8 @@ public: if (is_local_path) { SimpleLogger().Write(logDEBUG) << "case3"; - start_index = phantom_node_pair.startPhantom.fwd_segment_position - 1; - end_index = phantom_node_pair.targetPhantom.fwd_segment_position - 1; + start_index = phantom_node_pair.startPhantom.fwd_segment_position; + end_index = phantom_node_pair.targetPhantom.fwd_segment_position; if (target_traversed_in_reverse) { SimpleLogger().Write(logDEBUG) << "case4"; @@ -301,11 +306,15 @@ public: BOOST_ASSERT( start_index >= 0 ); // BOOST_ASSERT( start_index <= end_index ); for( - unsigned i = start_index; + int i = start_index; i != end_index; ( start_index < end_index ? ++i :--i) ) { - SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); + BOOST_ASSERT( i >= -1 ); + if ( i >= 0 ) + { + SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); + } unpacked_path.push_back( PathData( id_vector[i], diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 6c2e40203..1778e00d7 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -113,12 +113,12 @@ public: SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.startPhantom.forward_node_id, - -distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), + 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.GetForwardWeightPlusOffset(), + distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), phantom_node_pair.startPhantom.forward_node_id ); } @@ -129,12 +129,12 @@ public: SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.startPhantom.reverse_node_id, - -distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), + 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.GetReverseWeightPlusOffset(), + distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), phantom_node_pair.startPhantom.reverse_node_id ); } @@ -369,8 +369,8 @@ public: for(unsigned i = 0; i < packed_legs1.size(); ++i){ BOOST_ASSERT( !phantom_nodes_vector.empty() ); - const bool at_beginning = (packed_legs1[i] == packed_legs1.front()); - const bool at_end = (packed_legs1[i] == packed_legs1.back()); + // const bool at_beginning = (packed_legs1[i] == packed_legs1.front()); + // const bool at_end = (packed_legs1[i] == packed_legs1.back()); BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i]; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index ce0a17ca4..41c6be4d7 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -446,6 +446,9 @@ unsigned readHSGRFromStream( 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) ); + + SimpleLogger().Write() << "number_of_nodes: " << number_of_nodes << ", number_of_edges: " << number_of_edges; + // BOOST_ASSERT_MSG( 0 != number_of_edges, "number of edges is zero"); node_list.resize(number_of_nodes + 1); hsgr_input_stream.read( @@ -459,6 +462,16 @@ unsigned readHSGRFromStream( number_of_edges*sizeof(EdgeT) ); hsgr_input_stream.close(); + + for(unsigned i = 0; i < number_of_nodes; ++i) + { + SimpleLogger().Write(logDEBUG) << "node_list[" << i << "]=" << node_list[i].firstEdge; + } + for(unsigned i = 0; i < number_of_edges; ++i) + { + SimpleLogger().Write(logDEBUG) << "edge_list[" << i << "]=(*," << edge_list[i].target << "), w: " << edge_list[i].data.distance; + } + return number_of_nodes; } diff --git a/prepare.cpp b/prepare.cpp index fcf1fd077..2f68a5573 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -181,7 +181,7 @@ int main (int argc, char *argv[]) { restrictionsInstream.close(); std::ifstream in; - in.open (input_path.c_str(), std::ifstream::in | std::ifstream::binary); + in.open(input_path.c_str(), std::ifstream::in|std::ifstream::binary); const std::string nodeOut = input_path.string() + ".nodes"; const std::string edgeOut = input_path.string() + ".edges"; @@ -327,86 +327,126 @@ int main (int argc, char *argv[]) { */ std::sort(contractedEdgeList.begin(), contractedEdgeList.end()); - unsigned numberOfNodes = 0; - unsigned numberOfEdges = contractedEdgeList.size(); + unsigned max_used_node_id = 0; + unsigned contracted_edge_count = contractedEdgeList.size(); SimpleLogger().Write() << "Serializing compacted graph of " << - numberOfEdges << + contracted_edge_count << " edges"; std::ofstream hsgr_output_stream(graphOut, std::ios::binary); hsgr_output_stream.write((char*)&uuid_orig, sizeof(UUID) ); - BOOST_FOREACH(const QueryEdge & edge, contractedEdgeList) { + BOOST_FOREACH(const QueryEdge & edge, contractedEdgeList) + { BOOST_ASSERT( UINT_MAX != edge.source ); BOOST_ASSERT( UINT_MAX != edge.target ); - if(edge.source > numberOfNodes) { - numberOfNodes = edge.source; - } - if(edge.target > numberOfNodes) { - numberOfNodes = edge.target; - } + + max_used_node_id = std::max(max_used_node_id, edge.source); + max_used_node_id = std::max(max_used_node_id, edge.target); } - numberOfNodes+=1; + SimpleLogger().Write(logDEBUG) << "input graph has " << edgeBasedNodeNumber << " nodes"; + SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes"; + max_used_node_id+=1; - std::vector< StaticGraph::_StrNode > _nodes; - _nodes.resize( numberOfNodes + 1 ); + std::vector< StaticGraph::_StrNode > node_array; + node_array.resize( edgeBasedNodeNumber + 1); + SimpleLogger().Write() << "Building node array"; StaticGraph::EdgeIterator edge = 0; StaticGraph::EdgeIterator position = 0; - for ( StaticGraph::NodeIterator node = 0; node < numberOfNodes; ++node ) { - StaticGraph::EdgeIterator lastEdge = edge; - while ( edge < numberOfEdges && contractedEdgeList[edge].source == node ) + StaticGraph::EdgeIterator lastEdge = edge; + + for ( StaticGraph::NodeIterator node = 0; node < max_used_node_id; ++node ) { + lastEdge = edge; + while ( edge < contracted_edge_count && contractedEdgeList[edge].source == node ) + { ++edge; - _nodes[node].firstEdge = position; //=edge + } + node_array[node].firstEdge = position; //=edge position += edge - lastEdge; //remove + SimpleLogger().Write(logDEBUG) << "node: " << node << ", edge: " << edge << ", position: " << position << ", lastEdge: " << lastEdge; } - _nodes.back().firstEdge = numberOfEdges; //sentinel element - ++numberOfNodes; + SimpleLogger().Write(logDEBUG) << "contracted_edge_count: " << contracted_edge_count << ", position: " << position << ", lastEdge: " << lastEdge; + SimpleLogger().Write(logDEBUG) << "marking range [" << max_used_node_id << "," << node_array.size() << ") as dummies"; - BOOST_ASSERT_MSG( - _nodes.size() == numberOfNodes, - "no. of nodes dont match" - ); + for (unsigned sentinel_counter = max_used_node_id; + sentinel_counter != node_array.size(); + ++sentinel_counter + ) + { + //sentinel element, guarded against underflow + node_array[sentinel_counter].firstEdge = contracted_edge_count; + SimpleLogger().Write(logDEBUG) << "node_array[" << sentinel_counter << "].firstEdge = " << node_array[sentinel_counter].firstEdge; + } + // node_array.back().firstEdge = contracted_edge_count; //sentinel element + // ++max_used_node_id; + + // BOOST_ASSERT_MSG( + // node_array.size() == max_used_node_id, + // "no. of nodes dont match" + // ); + + for(unsigned i = 0; i < node_array.size(); ++i) + { + SimpleLogger().Write() << "node_array[" << i << "].firstEdge = " << node_array[i].firstEdge; + } + + unsigned node_array_size = node_array.size(); //serialize crc32, aka checksum hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); - //serialize number f nodes - hsgr_output_stream.write((char*) &numberOfNodes, sizeof(unsigned)); + //serialize number of nodes + hsgr_output_stream.write((char*) &node_array_size, sizeof(unsigned)); //serialize number of edges - hsgr_output_stream.write((char*) &position, sizeof(unsigned)); + hsgr_output_stream.write((char*) &contracted_edge_count, sizeof(unsigned)); //serialize all nodes - hsgr_output_stream.write((char*) &_nodes[0], sizeof(StaticGraph::_StrNode)*(numberOfNodes)); + hsgr_output_stream.write((char*) &node_array[0], sizeof(StaticGraph::_StrNode)*node_array_size); //serialize all edges - --numberOfNodes; + SimpleLogger().Write() << "Building edge array"; edge = 0; int usedEdgeCounter = 0; - SimpleLogger().Write() << "Building Node Array"; + + for(unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) + { + SimpleLogger().Write(logDEBUG) << ">[" << edge << "] (" << contractedEdgeList[edge].source << "," << contractedEdgeList[edge].target << ")"; + } + StaticGraph::_StrEdge currentEdge; - for ( StaticGraph::NodeIterator node = 0; node < numberOfNodes; ++node ) { - for ( StaticGraph::EdgeIterator i = _nodes[node].firstEdge, e = _nodes[node+1].firstEdge; i != e; ++i ) { - assert(node != contractedEdgeList[edge].target); + for(unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) + { + // for ( StaticGraph::NodeIterator node = 0; node < max_used_node_id; ++node ) { + // for ( StaticGraph::EdgeIterator i = node_array[node].firstEdge, e = node_array[node+1].firstEdge; i != e; ++i ) { + // BOOST_ASSERT(node == contractedEdgeList[edge].source) + // no eigen loops + BOOST_ASSERT(contractedEdgeList[edge].source != contractedEdgeList[edge].target); currentEdge.target = contractedEdgeList[edge].target; currentEdge.data = contractedEdgeList[edge].data; + + // every target needs to be valid + BOOST_ASSERT(currentEdge.target < max_used_node_id); if(currentEdge.data.distance <= 0) { SimpleLogger().Write(logWARNING) << - "Edge: " << i << + "Edge: " << edge << ",source: " << contractedEdgeList[edge].source << ", target: " << contractedEdgeList[edge].target << ", dist: " << currentEdge.data.distance; SimpleLogger().Write(logWARNING) << - "Failed at edges of node " << node << - " of " << numberOfNodes; + "Failed at adjacency list of node " << contractedEdgeList[edge].source << "/" << node_array.size()-1; return 1; } //Serialize edges + SimpleLogger().Write(logDEBUG) << "edge[" << edge << "], (" << contractedEdgeList[edge].source << "," << currentEdge.target << "), w: " << currentEdge.data.distance << + "shortcut: " << (currentEdge.data.shortcut ? "y" : "n"); hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); - ++edge; + // ++edge; ++usedEdgeCounter; } - } + // } + hsgr_output_stream.close(); + SimpleLogger().Write() << "Preprocessing : " << (get_timestamp() - startupTime) << " seconds"; SimpleLogger().Write() << "Expansion : " << @@ -417,11 +457,10 @@ int main (int argc, char *argv[]) { (edgeBasedNodeNumber/contraction_duration) << " nodes/sec and " << usedEdgeCounter/contraction_duration << " edges/sec"; - hsgr_output_stream.close(); //cleanedEdgeList.clear(); - _nodes.clear(); + node_array.clear(); SimpleLogger().Write() << "finished preprocessing"; - } catch(boost::program_options::too_many_positional_options_error& e) { + } catch(boost::program_options::too_many_positional_options_error&) { SimpleLogger().Write(logWARNING) << "Only one file can be specified"; return 1; } catch(boost::program_options::error& e) { From 9cc49f6ff39488b885db1640c5d2c964f0795ef9 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Mar 2014 18:27:39 +0100 Subject: [PATCH 32/89] remove debug output --- DataStructures/StaticGraph.h | 10 ---------- Server/DataStructures/InternalDataFacade.h | 8 ++++---- Util/GraphLoader.h | 9 --------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 4665dd102..e3445c583 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -101,12 +101,6 @@ public: _nodes.swap(nodes); _edges.swap(edges); - for(unsigned i = 0; i < _numNodes; ++i) - { - SimpleLogger().Write(logDEBUG) << "edges of " << i << ": [" << BeginEdges(i) << "," << EndEdges(i) << ")"; - } - - #ifndef NDEBUG Percent p(GetNumberOfNodes()); for(unsigned u = 0; u < GetNumberOfNodes(); ++u) { @@ -135,10 +129,6 @@ public: } p.printIncrement(); } - for(unsigned i = 0; i < _numNodes; ++i) - { - SimpleLogger().Write(logDEBUG) << "edges of " << i << ": [" << BeginEdges(i) << "," << EndEdges(i) << ")"; - } #endif } diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 11f26734d..d04d1dba9 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -173,9 +173,9 @@ private: sizeof(OriginalEdgeData) ); m_via_node_list[i] = current_edge_data.via_node; - if(current_edge_data.via_node == 0 && current_edge_data.compressed_geometry) { - SimpleLogger().Write() << "0 at index " << i; - } + // if(current_edge_data.via_node == 0 && current_edge_data.compressed_geometry) { + // SimpleLogger().Write() << "0 at index " << i; + // } m_name_ID_list[i] = current_edge_data.name_id; m_turn_instruction_list[i] = current_edge_data.turn_instruction; @@ -184,7 +184,7 @@ private: ++compressed; } } - SimpleLogger().Write(logDEBUG) << "compressed: " << compressed; + // SimpleLogger().Write(logDEBUG) << "compressed: " << compressed; edges_input_stream.close(); } diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 41c6be4d7..dc8d73139 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -463,15 +463,6 @@ unsigned readHSGRFromStream( ); hsgr_input_stream.close(); - for(unsigned i = 0; i < number_of_nodes; ++i) - { - SimpleLogger().Write(logDEBUG) << "node_list[" << i << "]=" << node_list[i].firstEdge; - } - for(unsigned i = 0; i < number_of_edges; ++i) - { - SimpleLogger().Write(logDEBUG) << "edge_list[" << i << "]=(*," << edge_list[i].target << "), w: " << edge_list[i].data.distance; - } - return number_of_nodes; } From 12b43d206c3a1bff035676c81c430405edebb11d Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Mar 2014 18:28:28 +0100 Subject: [PATCH 33/89] unpack properly when source and target are reversed on same edge --- RoutingAlgorithms/BasicRoutingInterface.h | 61 ++++++++++------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index bb9391efe..7e777d675 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -67,10 +67,10 @@ public: ) const { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); - SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; + // SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; if(reverse_heap.WasInserted(node) ){ const int new_distance = reverse_heap.GetKey(node) + distance; - SimpleLogger().Write(logDEBUG) << "new_distance: " << new_distance; + // SimpleLogger().Write(logDEBUG) << "new_distance: " << new_distance; if(new_distance < *upper_bound ){ if( new_distance >= 0 ) { *middle_node_id = node; @@ -80,7 +80,7 @@ public: } if( (distance-edge_expansion_offset) > *upper_bound ){ - SimpleLogger().Write() << "found path"; + // SimpleLogger().Write() << "found path"; forward_heap.DeleteAll(); return; } @@ -101,13 +101,13 @@ public: if(forward_heap.WasInserted( to )) { if(forward_heap.GetKey( to ) + edge_weight < distance) { - SimpleLogger().Write(logDEBUG) << "stalled"; + // SimpleLogger().Write(logDEBUG) << "stalled"; return; } } } } - SimpleLogger().Write(logDEBUG) << "done stalling"; + // SimpleLogger().Write(logDEBUG) << "done stalling"; for( EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node); edge < end_edge; @@ -125,14 +125,14 @@ public: //New Node discovered -> Add to Heap + Node Info Storage if ( !forward_heap.WasInserted( to ) ) { - SimpleLogger().Write() << "insert (" << node << "," << to << "), distance: " << to_distance << ", edge id: " << edge; + // SimpleLogger().Write() << "insert (" << node << "," << to << "), distance: " << to_distance << ", edge id: " << edge; forward_heap.Insert( to, to_distance, node ); } //Found a shorter Path -> Update distance else if ( to_distance < forward_heap.GetKey( to ) ) { forward_heap.GetData( to ).parent = node; forward_heap.DecreaseKey( to, to_distance ); - SimpleLogger().Write() << "decrease (" << node << "," << to << "), distance: " << to_distance; + // SimpleLogger().Write() << "decrease (" << node << "," << to << "), distance: " << to_distance; //new parent } } @@ -146,7 +146,7 @@ public: const PhantomNodes & phantom_node_pair, std::vector & unpacked_path ) const { - SimpleLogger().Write(logDEBUG) << "packed_path.size: " << packed_path.size(); + // SimpleLogger().Write(logDEBUG) << "packed_path.size: " << packed_path.size(); const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.startPhantom.forward_node_id); const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.targetPhantom.forward_node_id); @@ -257,64 +257,55 @@ public: } } if(SPECIAL_EDGEID != phantom_node_pair.targetPhantom.packed_geometry_id ) { - SimpleLogger().Write(logDEBUG) << "unpacking last segment " << phantom_node_pair.targetPhantom.packed_geometry_id; - SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << (start_traversed_in_reverse ? "y" : "n"); - SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); - SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.fwd_segment_position: " << phantom_node_pair.startPhantom.fwd_segment_position << ", " << - "phantom_node_pair.targetPhantom.fwd_segment_position: " << phantom_node_pair.targetPhantom.fwd_segment_position; + // SimpleLogger().Write(logDEBUG) << "unpacking last segment " << phantom_node_pair.targetPhantom.packed_geometry_id; + // SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << (start_traversed_in_reverse ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.fwd_segment_position: " << phantom_node_pair.startPhantom.fwd_segment_position << ", " << + // "phantom_node_pair.targetPhantom.fwd_segment_position: " << phantom_node_pair.targetPhantom.fwd_segment_position; std::vector id_vector; facade->GetUncompressedGeometry(phantom_node_pair.targetPhantom.packed_geometry_id, id_vector); if( target_traversed_in_reverse ) { std::reverse(id_vector.begin(), id_vector.end() ); } - SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); - SimpleLogger().Write(logDEBUG) << "unpacked_path.empty()=" << (unpacked_path.empty() ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); + // SimpleLogger().Write(logDEBUG) << "unpacked_path.empty()=" << (unpacked_path.empty() ? "y" : "n"); const bool is_local_path = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty(); - SimpleLogger().Write(logDEBUG) << "is_local_path: " << (is_local_path ? "y" : "n"); - - - // const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1 : phantom_node_pair.startPhantom.fwd_segment_position ) : 0 ); + // SimpleLogger().Write(logDEBUG) << "is_local_path: " << (is_local_path ? "y" : "n"); int start_index = 0; int end_index = phantom_node_pair.targetPhantom.fwd_segment_position; - SimpleLogger().Write(logDEBUG) << "case1"; + // SimpleLogger().Write(logDEBUG) << "case1"; if (target_traversed_in_reverse) { - // start_index = id_vector.size() -1; end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position; - // if (is_local_path) - // { - // start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position -1; - // } } if (is_local_path) { - SimpleLogger().Write(logDEBUG) << "case3"; + // SimpleLogger().Write(logDEBUG) << "case3"; start_index = phantom_node_pair.startPhantom.fwd_segment_position; end_index = phantom_node_pair.targetPhantom.fwd_segment_position; if (target_traversed_in_reverse) { - SimpleLogger().Write(logDEBUG) << "case4"; - start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1; - end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position - 1; + // SimpleLogger().Write(logDEBUG) << "case4"; + start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position; + end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position; } } - SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; + // SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; BOOST_ASSERT( start_index >= 0 ); - // BOOST_ASSERT( start_index <= end_index ); for( int i = start_index; i != end_index; ( start_index < end_index ? ++i :--i) ) { BOOST_ASSERT( i >= -1 ); - if ( i >= 0 ) - { - SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); - } + // if ( i >= 0 ) + // { + // SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); + // } unpacked_path.push_back( PathData( id_vector[i], From bcaea1a6172efaa6200ef11049a5d102430ff818 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Mar 2014 19:19:33 +0100 Subject: [PATCH 34/89] remove debug output --- Contractor/EdgeBasedGraphFactory.cpp | 32 ++++++++++++++-------------- prepare.cpp | 23 ++++++++++---------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 782684b4d..806668d09 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -371,14 +371,14 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( forward_data.distance >= temp_sum ); forward_dist_prefix_sum[i] = forward_data.distance - temp_sum; } - BOOST_ASSERT( forward_data.distance == temp_sum ); + // BOOST_ASSERT( forward_data.distance == temp_sum ); temp_sum = 0; for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { temp_sum += reverse_geometry[i].second; BOOST_ASSERT( reverse_data.distance >= temp_sum ); reverse_dist_prefix_sum[i] = reverse_data.distance - temp_sum; } - BOOST_ASSERT( reverse_data.distance == temp_sum ); + // BOOST_ASSERT( reverse_data.distance == temp_sum ); BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); @@ -570,9 +570,16 @@ void EdgeBasedGraphFactory::Run( BOOST_ASSERT( 0 != reverse_weight1 ); BOOST_ASSERT( 0 != forward_weight2 ); + const bool add_traffic_signal_penalty = (m_traffic_lights.find(v) != m_traffic_lights.end()); + // add weight of e2's to e1 m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance; m_node_based_graph->GetEdgeData(reverse_e1).distance += rev_edge_data2.distance; + if (add_traffic_signal_penalty) + { + m_node_based_graph->GetEdgeData(forward_e1).distance += speed_profile.trafficSignalPenalty; + m_node_based_graph->GetEdgeData(reverse_e1).distance += speed_profile.trafficSignalPenalty; + } // extend e1's to targets of e2's m_node_based_graph->SetTarget(forward_e1, w); @@ -595,7 +602,7 @@ void EdgeBasedGraphFactory::Run( forward_e2, v, w, - forward_weight1, + forward_weight1 + (add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty :0), forward_weight2 ); m_geometry_compressor.CompressEdge( @@ -603,8 +610,8 @@ void EdgeBasedGraphFactory::Run( reverse_e2, v, u, - reverse_weight1, - reverse_weight2 + reverse_weight1 , + reverse_weight2 + (add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty :0) ); ++removed_node_count; @@ -808,21 +815,14 @@ void EdgeBasedGraphFactory::Run( const EdgeData & edge_data1 = m_node_based_graph->GetEdgeData(e1); const EdgeData & edge_data2 = m_node_based_graph->GetEdgeData(e2); - // BOOST_ASSERT( - // edge_data1.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() - // ); - // BOOST_ASSERT( - // edge_data2.edgeBasedNodeID < m_node_based_graph->GetNumberOfEdges() - // ); - BOOST_ASSERT( - edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID - ); - BOOST_ASSERT( edge_data1.forward ); - BOOST_ASSERT( edge_data2.forward ); + BOOST_ASSERT(edge_data1.edgeBasedNodeID != edge_data2.edgeBasedNodeID); + BOOST_ASSERT(edge_data1.forward); + BOOST_ASSERT(edge_data2.forward); // the following is the core of the loop. unsigned distance = edge_data1.distance; if( m_traffic_lights.find(v) != m_traffic_lights.end() ) { + SimpleLogger().Write(logDEBUG) << "penalty: " << speed_profile.trafficSignalPenalty; distance += speed_profile.trafficSignalPenalty; } const int turn_penalty = GetTurnPenalty(u, v, w, lua_state); diff --git a/prepare.cpp b/prepare.cpp index 2f68a5573..f21b3c566 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -222,6 +222,7 @@ int main (int argc, char *argv[]) { return 1; } speedProfile.trafficSignalPenalty = 10*lua_tointeger(myLuaState, -1); + SimpleLogger().Write(logDEBUG) << "traffic_signal_penalty: " << speedProfile.trafficSignalPenalty; if(0 != luaL_dostring( myLuaState, "return u_turn_penalty\n")) { std::cerr << @@ -364,11 +365,11 @@ int main (int argc, char *argv[]) { } node_array[node].firstEdge = position; //=edge position += edge - lastEdge; //remove - SimpleLogger().Write(logDEBUG) << "node: " << node << ", edge: " << edge << ", position: " << position << ", lastEdge: " << lastEdge; + // SimpleLogger().Write(logDEBUG) << "node: " << node << ", edge: " << edge << ", position: " << position << ", lastEdge: " << lastEdge; } - SimpleLogger().Write(logDEBUG) << "contracted_edge_count: " << contracted_edge_count << ", position: " << position << ", lastEdge: " << lastEdge; - SimpleLogger().Write(logDEBUG) << "marking range [" << max_used_node_id << "," << node_array.size() << ") as dummies"; + // SimpleLogger().Write(logDEBUG) << "contracted_edge_count: " << contracted_edge_count << ", position: " << position << ", lastEdge: " << lastEdge; + // SimpleLogger().Write(logDEBUG) << "marking range [" << max_used_node_id << "," << node_array.size() << ") as dummies"; for (unsigned sentinel_counter = max_used_node_id; sentinel_counter != node_array.size(); @@ -377,7 +378,7 @@ int main (int argc, char *argv[]) { { //sentinel element, guarded against underflow node_array[sentinel_counter].firstEdge = contracted_edge_count; - SimpleLogger().Write(logDEBUG) << "node_array[" << sentinel_counter << "].firstEdge = " << node_array[sentinel_counter].firstEdge; + // SimpleLogger().Write(logDEBUG) << "node_array[" << sentinel_counter << "].firstEdge = " << node_array[sentinel_counter].firstEdge; } // node_array.back().firstEdge = contracted_edge_count; //sentinel element // ++max_used_node_id; @@ -387,10 +388,10 @@ int main (int argc, char *argv[]) { // "no. of nodes dont match" // ); - for(unsigned i = 0; i < node_array.size(); ++i) - { - SimpleLogger().Write() << "node_array[" << i << "].firstEdge = " << node_array[i].firstEdge; - } + // for(unsigned i = 0; i < node_array.size(); ++i) + // { + // SimpleLogger().Write() << "node_array[" << i << "].firstEdge = " << node_array[i].firstEdge; + // } unsigned node_array_size = node_array.size(); @@ -410,7 +411,7 @@ int main (int argc, char *argv[]) { for(unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) { - SimpleLogger().Write(logDEBUG) << ">[" << edge << "] (" << contractedEdgeList[edge].source << "," << contractedEdgeList[edge].target << ")"; + // SimpleLogger().Write(logDEBUG) << ">[" << edge << "] (" << contractedEdgeList[edge].source << "," << contractedEdgeList[edge].target << ")"; } StaticGraph::_StrEdge currentEdge; @@ -438,8 +439,8 @@ int main (int argc, char *argv[]) { return 1; } //Serialize edges - SimpleLogger().Write(logDEBUG) << "edge[" << edge << "], (" << contractedEdgeList[edge].source << "," << currentEdge.target << "), w: " << currentEdge.data.distance << - "shortcut: " << (currentEdge.data.shortcut ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "edge[" << edge << "], (" << contractedEdgeList[edge].source << "," << currentEdge.target << "), w: " << currentEdge.data.distance << + // "shortcut: " << (currentEdge.data.shortcut ? "y" : "n"); hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); // ++edge; ++usedEdgeCounter; From 48d23194af77a415ca4eb6ae6b951c21abc9b373 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Mar 2014 19:20:00 +0100 Subject: [PATCH 35/89] fix traffic signal penalty in compressed graph --- Contractor/GeometryCompressor.cpp | 56 +++++++++++++++++++------------ profiles/car.lua | 2 +- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index b9cb1739a..9691a6f44 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -36,24 +36,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. int current_free_list_maximum = 0; int UniqueNumber () { return ++current_free_list_maximum; } -GeometryCompressor::GeometryCompressor() { +GeometryCompressor::GeometryCompressor() +{ m_free_list.reserve(100); IncreaseFreeList(); } -void GeometryCompressor::IncreaseFreeList() { +void GeometryCompressor::IncreaseFreeList() +{ m_compressed_geometries.resize(m_compressed_geometries.size() + 100); - for(unsigned i = 100; i > 0; --i) { + for(unsigned i = 100; i > 0; --i) + { m_free_list.push_back(current_free_list_maximum); ++current_free_list_maximum; } } -bool GeometryCompressor::HasEntryForID(const EdgeID edge_id) const { +bool GeometryCompressor::HasEntryForID(const EdgeID edge_id) const +{ return (m_edge_id_to_list_index_map.find(edge_id) != m_edge_id_to_list_index_map.end()); } -unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const { +unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const +{ boost::unordered_map::const_iterator map_iterator; map_iterator = m_edge_id_to_list_index_map.find(edge_id); BOOST_ASSERT( map_iterator != m_edge_id_to_list_index_map.end() ); @@ -61,9 +66,8 @@ unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const { return map_iterator->second; } -void GeometryCompressor::SerializeInternalVector( - const std::string & path -) const { +void GeometryCompressor::SerializeInternalVector(const std::string & path) const +{ std::ofstream geometry_out_stream( path.c_str(), std::ios::binary ); const unsigned number_of_compressed_geometries = m_compressed_geometries.size()+1; @@ -77,7 +81,8 @@ void GeometryCompressor::SerializeInternalVector( // write indices array unsigned prefix_sum_of_list_indices = 0; - for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) { + for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) + { geometry_out_stream.write( (char*)&prefix_sum_of_list_indices, sizeof(unsigned) @@ -103,12 +108,14 @@ void GeometryCompressor::SerializeInternalVector( SimpleLogger().Write(logDEBUG) << "number of geometry nodes: " << prefix_sum_of_list_indices; unsigned control_sum = 0; // write compressed geometries - for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) { + for (unsigned i = 0; i < m_compressed_geometries.size(); ++i) + { const std::vector & current_vector = m_compressed_geometries[i]; const unsigned unpacked_size = current_vector.size(); control_sum += unpacked_size; BOOST_ASSERT( UINT_MAX != unpacked_size ); - BOOST_FOREACH(const CompressedNode current_node, current_vector ) { + BOOST_FOREACH (const CompressedNode current_node, current_vector) + { geometry_out_stream.write( (char*)&(current_node.first), sizeof(NodeID) @@ -145,11 +152,11 @@ void GeometryCompressor::CompressEdge( // 2. find list for edge_id_2, if yes add all elements and delete it // Add via node id. List is created if it does not exist - if( - !HasEntryForID(edge_id_1) - ) { + if (!HasEntryForID(edge_id_1)) + { // create a new entry in the map - if( 0 == m_free_list.size() ) { + if (0 == m_free_list.size()) + { // make sure there is a place to put the entries // SimpleLogger().Write() << "increased free list"; IncreaseFreeList(); @@ -166,14 +173,16 @@ void GeometryCompressor::CompressEdge( std::vector & edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1]; - if( edge_bucket_list1.empty() ) { + if (edge_bucket_list1.empty()) + { edge_bucket_list1.push_back( std::make_pair(via_node_id, weight1) ); } BOOST_ASSERT( 0 < edge_bucket_list1.size() ); BOOST_ASSERT( !edge_bucket_list1.empty() ); - if( HasEntryForID(edge_id_2) ) { + if (HasEntryForID(edge_id_2)) + { // second edge is not atomic anymore const unsigned list_to_remove_index = GetPositionForID(edge_id_2); BOOST_ASSERT( list_to_remove_index < m_compressed_geometries.size() ); @@ -194,20 +203,24 @@ void GeometryCompressor::CompressEdge( BOOST_ASSERT( 0 == edge_bucket_list2.size() ); m_free_list.push_back(list_to_remove_index); BOOST_ASSERT( list_to_remove_index == m_free_list.back() ); - } else { + } + else + { // we are certain that the second edge is atomic. edge_bucket_list1.push_back( std::make_pair(target_node_id, weight2) ); } } -void GeometryCompressor::PrintStatistics() const { +void GeometryCompressor::PrintStatistics() const +{ unsigned number_of_compressed_geometries = 0; const unsigned compressed_edges = m_compressed_geometries.size(); BOOST_ASSERT( m_compressed_geometries.size() + m_free_list.size() > 0 ); unsigned long longest_chain_length = 0; - BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) { + BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) + { number_of_compressed_geometries += current_vector.size(); longest_chain_length = std::max(longest_chain_length, current_vector.size()); } @@ -225,7 +238,8 @@ void GeometryCompressor::PrintStatistics() const { const std::vector & GeometryCompressor::GetBucketReference( const EdgeID edge_id -) const { +) const +{ const unsigned index = m_edge_id_to_list_index_map.at( edge_id ); return m_compressed_geometries.at( index ); } diff --git a/profiles/car.lua b/profiles/car.lua index 4a8564eb6..d57a6544e 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -32,7 +32,7 @@ speed_profile = { ["default"] = 10 } -local take_minimum_of_speeds = false +local take_minimum_of_speeds = false local obey_oneway = true local obey_bollards = true local use_turn_restrictions = true From 26397e46927c531ab88027c8acf11d3d3e70a4a4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 21 Mar 2014 19:54:30 +0100 Subject: [PATCH 36/89] remove debug output --- Contractor/EdgeBasedGraphFactory.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 806668d09..680f8ce2a 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -822,7 +822,6 @@ void EdgeBasedGraphFactory::Run( // the following is the core of the loop. unsigned distance = edge_data1.distance; if( m_traffic_lights.find(v) != m_traffic_lights.end() ) { - SimpleLogger().Write(logDEBUG) << "penalty: " << speed_profile.trafficSignalPenalty; distance += speed_profile.trafficSignalPenalty; } const int turn_penalty = GetTurnPenalty(u, v, w, lua_state); From b429d9f5097a421cc045f66ee665cc291374c2f7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 24 Mar 2014 16:46:31 +0100 Subject: [PATCH 37/89] remove unreachable code --- Extractor/ExtractionContainers.cpp | 1 - Server/RequestParser.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index c8f801705..44c4d6895 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -362,7 +362,6 @@ void ExtractionContainers::PrepareData( break; default: throw OSRMException("edge has broken direction"); - break; } file_out_stream.write( (char*)&integer_weight, sizeof(int) diff --git a/Server/RequestParser.cpp b/Server/RequestParser.cpp index 8b2b1a985..256fa5f0e 100644 --- a/Server/RequestParser.cpp +++ b/Server/RequestParser.cpp @@ -239,8 +239,6 @@ boost::tribool RequestParser::consume( } case expecting_newline_3: return (input == '\n'); - default: - return false; } } From 776ac3bb2ab2c76ecbff6aa6662787bcef569810 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 25 Mar 2014 16:40:24 +0100 Subject: [PATCH 38/89] remove superflous include --- Library/OSRM.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Library/OSRM.h b/Library/OSRM.h index be137b8c5..599a93524 100644 --- a/Library/OSRM.h +++ b/Library/OSRM.h @@ -28,8 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OSRM_H #define OSRM_H -#include - #include #include #include From 2861bacd2abb5e6b69ceb0aec5eae389c3af91d1 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 25 Mar 2014 17:48:25 +0100 Subject: [PATCH 39/89] fix check for invalid phantom nodes (20 failed left) --- DataStructures/PhantomNodes.h | 8 ++++---- RoutingAlgorithms/AlternativePathRouting.h | 2 +- RoutingAlgorithms/ShortestPathRouting.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 9b7076f08..e74af6db5 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -113,7 +113,7 @@ struct PhantomNode { }; struct PhantomNodes { - //TODO: rename to lower-case non-camel + //TODO: rename to lower-case non-camel source_*,target_* PhantomNode startPhantom; PhantomNode targetPhantom; void Reset() { @@ -125,9 +125,9 @@ struct PhantomNodes { return (startPhantom.forward_node_id == targetPhantom.forward_node_id); } - //TODO: Rename to: BothPhantomNodesAreInvalid - bool AtLeastOnePhantomNodeIsUINTMAX() const { - return (startPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.reverse_node_id == SPECIAL_NODEID); + bool AtLeastOnePhantomNodeIsInvalid() const { + return ((startPhantom.forward_node_id == SPECIAL_NODEID) && (startPhantom.reverse_node_id == SPECIAL_NODEID)) || + ((targetPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.reverse_node_id == SPECIAL_NODEID)); } bool PhantomNodesHaveEqualLocation() const { diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index cd10e28ba..05a2895e4 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -87,7 +87,7 @@ public: RawRouteData & raw_route_data ) { SimpleLogger().Write(logDEBUG) << "alt path routing"; - if( //phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() || + if( //phantom_node_pair.AtLeastOnePhantomNodeIsInvalid() || phantom_node_pair.PhantomNodesHaveEqualLocation() ) { // raw_route_data.lengthOfShortestPath = INVALID_EDGE_WEIGHT; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 1778e00d7..2dbcea798 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -60,7 +60,7 @@ public: const PhantomNodes & phantom_node_pair, phantom_nodes_vector ){ - if( phantom_node_pair.AtLeastOnePhantomNodeIsUINTMAX() ) { + if( phantom_node_pair.AtLeastOnePhantomNodeIsInvalid() ) { // raw_route_data.lengthOfShortestPath = INT_MAX; // raw_route_data.lengthOfAlternativePath = INT_MAX; SimpleLogger().Write(logDEBUG) << "returning early"; From 7b5902a580e15c54c5729f44779465258fbb9ddb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 25 Mar 2014 18:06:05 +0100 Subject: [PATCH 40/89] rename phantom nodes members --- DataStructures/PhantomNodes.h | 71 +++++++++++-------- Descriptors/GPXDescriptor.h | 8 +-- Descriptors/JSONDescriptor.h | 18 ++--- Plugins/ViaRoutePlugin.h | 8 +-- RoutingAlgorithms/AlternativePathRouting.h | 62 ++++++++--------- RoutingAlgorithms/BasicRoutingInterface.h | 34 +++++----- RoutingAlgorithms/ShortestPathRouting.h | 79 +++++++++++----------- 7 files changed, 146 insertions(+), 134 deletions(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index e74af6db5..5396c3e60 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -34,9 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct PhantomNode { PhantomNode() : - forward_node_id( SPECIAL_NODEID ), - reverse_node_id( SPECIAL_NODEID ), - name_id( std::numeric_limits::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), @@ -59,18 +59,20 @@ struct PhantomNode { unsigned short fwd_segment_position; - int GetForwardWeightPlusOffset() const { + int GetForwardWeightPlusOffset() const + { SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight; return reverse_offset + forward_weight; } - int GetReverseWeightPlusOffset() const { + int GetReverseWeightPlusOffset() const + { SimpleLogger().Write(logDEBUG) << "->rev_offset: " << reverse_offset << ", weight: " << reverse_weight; - return forward_offset + reverse_weight; } - void Reset() { + void Reset() + { forward_node_id = SPECIAL_NODEID; name_id = SPECIAL_NODEID; forward_weight = INVALID_EDGE_WEIGHT; @@ -81,16 +83,19 @@ struct PhantomNode { location.Reset(); } - bool isBidirected() const { - return ( forward_node_id != SPECIAL_NODEID ) && - ( reverse_node_id != SPECIAL_NODEID ); + bool isBidirected() const + { + return (forward_node_id != SPECIAL_NODEID) && + (reverse_node_id != SPECIAL_NODEID); } - bool IsCompressed() const { + bool IsCompressed() const + { return (forward_offset != 0) || (reverse_offset != 0); } - bool isValid(const unsigned numberOfNodes) const { + bool isValid(const unsigned numberOfNodes) const + { return location.isValid() && ( @@ -107,39 +112,45 @@ struct PhantomNode { ); } - bool operator==(const PhantomNode & other) const { + bool operator==(const PhantomNode & other) const + { return location == other.location; } }; -struct PhantomNodes { +struct PhantomNodes +{ //TODO: rename to lower-case non-camel source_*,target_* - PhantomNode startPhantom; - PhantomNode targetPhantom; - void Reset() { - startPhantom.Reset(); - targetPhantom.Reset(); + PhantomNode source_phantom; + PhantomNode target_phantom; + void Reset() + { + source_phantom.Reset(); + target_phantom.Reset(); } - bool PhantomsAreOnSameNodeBasedEdge() const { - return (startPhantom.forward_node_id == targetPhantom.forward_node_id); + bool PhantomsAreOnSameNodeBasedEdge() const + { + return (source_phantom.forward_node_id == target_phantom.forward_node_id); } - bool AtLeastOnePhantomNodeIsInvalid() const { - return ((startPhantom.forward_node_id == SPECIAL_NODEID) && (startPhantom.reverse_node_id == SPECIAL_NODEID)) || - ((targetPhantom.forward_node_id == SPECIAL_NODEID) && (targetPhantom.reverse_node_id == SPECIAL_NODEID)); + bool AtLeastOnePhantomNodeIsInvalid() const + { + return ((source_phantom.forward_node_id == SPECIAL_NODEID) && (source_phantom.reverse_node_id == SPECIAL_NODEID)) || + ((target_phantom.forward_node_id == SPECIAL_NODEID) && (target_phantom.reverse_node_id == SPECIAL_NODEID)); } - bool PhantomNodesHaveEqualLocation() const { - return startPhantom == targetPhantom; + bool PhantomNodesHaveEqualLocation() const + { + return source_phantom == target_phantom; } }; inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) { - // out << "Node1: " << pn.startPhantom.forward_node_id << "\n"; - // out << "Node2: " << pn.targetPhantom.reverse_node_id << "\n"; - out << "start_coord: " << pn.startPhantom.location << "\n"; - out << "target_coord: " << pn.targetPhantom.location << std::endl; + // out << "Node1: " << pn.source_phantom.forward_node_id << "\n"; + // out << "Node2: " << pn.target_phantom.reverse_node_id << "\n"; + out << "source_coord: " << pn.source_phantom.location << "\n"; + out << "target_coord: " << pn.target_phantom.location << std::endl; return out; } diff --git a/Descriptors/GPXDescriptor.h b/Descriptors/GPXDescriptor.h index 105a09abf..7d9a6d680 100644 --- a/Descriptors/GPXDescriptor.h +++ b/Descriptors/GPXDescriptor.h @@ -65,12 +65,12 @@ public: (raw_route.unpacked_path_segments[0].size()); if( found_route ) { FixedPointCoordinate::convertInternalLatLonToString( - phantom_node_list.startPhantom.location.lat, + phantom_node_list.source_phantom.location.lat, tmp ); reply.content.push_back(""); @@ -90,12 +90,12 @@ public: } // Add the via point or the end coordinate FixedPointCoordinate::convertInternalLatLonToString( - phantom_node_list.targetPhantom.location.lat, + phantom_node_list.target_phantom.location.lat, tmp ); reply.content.push_back(""); diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 2d367a9cc..5415cc5ed 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -101,7 +101,7 @@ public: description_factory.AppendSegment(current_coordinate, path_data ); ++added_element_count; } - // description_factory.SetEndSegment( leg_phantoms.targetPhantom ); + // description_factory.SetEndSegment( leg_phantoms.target_phantom ); ++added_element_count; BOOST_ASSERT( (int)(route_leg.size() + 1) == added_element_count ); return added_element_count; @@ -127,7 +127,7 @@ public: return; } - description_factory.SetStartSegment(phantom_nodes.startPhantom); + description_factory.SetStartSegment(phantom_nodes.source_phantom); reply.content.push_back("0," "\"status_message\": \"Found route between points\","); @@ -142,7 +142,7 @@ public: added_segments + shortest_leg_end_indices.back() ); } - description_factory.SetEndSegment(phantom_nodes.targetPhantom); + description_factory.SetEndSegment(phantom_nodes.target_phantom); description_factory.Run(facade, config.zoom_level); reply.content.push_back("\"route_geometry\": "); @@ -195,13 +195,13 @@ public: //only one alternative route is computed at this time, so this is hardcoded if(raw_route.lengthOfAlternativePath != INT_MAX) { - alternate_descriptionFactory.SetStartSegment(phantom_nodes.startPhantom); + alternate_descriptionFactory.SetStartSegment(phantom_nodes.source_phantom); //Get all the coordinates for the computed route BOOST_FOREACH(const PathData & path_data, raw_route.unpacked_alternative) { current = facade->GetCoordinateOfNode(path_data.node); alternate_descriptionFactory.AppendSegment(current, path_data ); } - alternate_descriptionFactory.SetEndSegment(phantom_nodes.targetPhantom); + alternate_descriptionFactory.SetEndSegment(phantom_nodes.target_phantom); } alternate_descriptionFactory.Run(facade, config.zoom_level); @@ -286,7 +286,7 @@ public: std::string tmp; FixedPointCoordinate::convertInternalReversedCoordinateToString( - raw_route.segmentEndCoordinates.front().startPhantom.location, + raw_route.segmentEndCoordinates.front().source_phantom.location, tmp ); reply.content.push_back("["); @@ -296,7 +296,7 @@ public: BOOST_FOREACH(const PhantomNodes & nodes, raw_route.segmentEndCoordinates) { tmp.clear(); FixedPointCoordinate::convertInternalReversedCoordinateToString( - nodes.targetPhantom.location, + nodes.target_phantom.location, tmp ); reply.content.push_back(",["); @@ -332,11 +332,11 @@ public: std::string hint; for(unsigned i = 0; i < raw_route.segmentEndCoordinates.size(); ++i) { reply.content.push_back("\""); - EncodeObjectToBase64(raw_route.segmentEndCoordinates[i].startPhantom, hint); + EncodeObjectToBase64(raw_route.segmentEndCoordinates[i].source_phantom, hint); reply.content.push_back(hint); reply.content.push_back("\", "); } - EncodeObjectToBase64(raw_route.segmentEndCoordinates.back().targetPhantom, hint); + EncodeObjectToBase64(raw_route.segmentEndCoordinates.back().target_phantom, hint); reply.content.push_back("\""); reply.content.push_back(hint); reply.content.push_back("\"]"); diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 5f25f20bc..6242f172e 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -112,8 +112,8 @@ public: PhantomNodes segmentPhantomNodes; for(unsigned i = 0; i < phantomNodeVector.size()-1; ++i) { - segmentPhantomNodes.startPhantom = phantomNodeVector[i]; - segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1]; + segmentPhantomNodes.source_phantom = phantomNodeVector[i]; + segmentPhantomNodes.target_phantom = phantomNodeVector[i+1]; rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes); } @@ -172,8 +172,8 @@ public: } PhantomNodes phantomNodes; - phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom; - phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom; + phantomNodes.source_phantom = rawRoute.segmentEndCoordinates[0].source_phantom; + phantomNodes.target_phantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].target_phantom; desc->SetConfig(descriptorConfig); desc->Run(rawRoute, phantomNodes, facade, reply); diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 05a2895e4..589bbb393 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -119,45 +119,45 @@ public: int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT; NodeID middle_node = SPECIAL_NODEID; - if(phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(); + if(phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( - phantom_node_pair.startPhantom.forward_node_id, - -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.startPhantom.forward_node_id + phantom_node_pair.source_phantom.forward_node_id, + -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), + phantom_node_pair.source_phantom.forward_node_id ); } - if(phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(); + if(phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( - phantom_node_pair.startPhantom.reverse_node_id, - -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), - phantom_node_pair.startPhantom.reverse_node_id + phantom_node_pair.source_phantom.reverse_node_id, + -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), + phantom_node_pair.source_phantom.reverse_node_id ); } - if(phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id << ", w: " << phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(); + if(phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( - phantom_node_pair.targetPhantom.forward_node_id, - phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.targetPhantom.forward_node_id + phantom_node_pair.target_phantom.forward_node_id, + phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(), + phantom_node_pair.target_phantom.forward_node_id ); } - if(phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id << ", w: " << phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(); + if(phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); reverse_heap1.Insert( - phantom_node_pair.targetPhantom.reverse_node_id, - phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), - phantom_node_pair.targetPhantom.reverse_node_id + phantom_node_pair.target_phantom.reverse_node_id, + phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(), + phantom_node_pair.target_phantom.reverse_node_id ); } const int forward_offset = super::ComputeEdgeOffset( - phantom_node_pair.startPhantom + phantom_node_pair.source_phantom ); const int reverse_offset = super::ComputeEdgeOffset( - phantom_node_pair.targetPhantom + phantom_node_pair.target_phantom ); SimpleLogger().Write(logDEBUG) << "fwd_offset: " << forward_offset << ", reverse_offset: " << reverse_offset; @@ -319,17 +319,17 @@ public: if( INVALID_EDGE_WEIGHT != upper_bound_to_shortest_path_distance ) { BOOST_ASSERT( !packed_shortest_path.empty() ); raw_route_data.unpacked_path_segments.resize(1); - // SimpleLogger().Write() << "fwd offset1: " << phantom_node_pair.startPhantom.fwd_segment_position; - // SimpleLogger().Write() << "fwd offset2: " << phantom_node_pair.startPhantom.rev_segment_position; - // SimpleLogger().Write() << "rev offset1: " << phantom_node_pair.targetPhantom.fwd_segment_position; - // SimpleLogger().Write() << "rev offset2: " << phantom_node_pair.targetPhantom.rev_segment_position; + // SimpleLogger().Write() << "fwd offset1: " << phantom_node_pair.source_phantom.fwd_segment_position; + // SimpleLogger().Write() << "fwd offset2: " << phantom_node_pair.source_phantom.rev_segment_position; + // SimpleLogger().Write() << "rev offset1: " << phantom_node_pair.target_phantom.fwd_segment_position; + // SimpleLogger().Write() << "rev offset2: " << phantom_node_pair.target_phantom.rev_segment_position; - // int start_offset = ( packed_shortest_path.front() == phantom_node_pair.startPhantom.forward_node_id ? 1 : -1 )*phantom_node_pair.startPhantom.fwd_segment_position; - // SimpleLogger().Write(logDEBUG) << "unpacking from index " << phantom_node_pair.startPhantom.fwd_segment_position; + // int start_offset = ( packed_shortest_path.front() == phantom_node_pair.source_phantom.forward_node_id ? 1 : -1 )*phantom_node_pair.source_phantom.fwd_segment_position; + // SimpleLogger().Write(logDEBUG) << "unpacking from index " << phantom_node_pair.source_phantom.fwd_segment_position; - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.forward_node_id: " << phantom_node_pair.startPhantom.forward_node_id; - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.reverse_node_id: " << phantom_node_pair.startPhantom.reverse_node_id; - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.targetPhantom.packed_geometry_id: " << phantom_node_pair.targetPhantom.packed_geometry_id; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.source_phantom.forward_node_id: " << phantom_node_pair.source_phantom.forward_node_id; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.source_phantom.reverse_node_id: " << phantom_node_pair.source_phantom.reverse_node_id; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.target_phantom.packed_geometry_id: " << phantom_node_pair.target_phantom.packed_geometry_id; // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); super::UnpackPath( diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 7e777d675..69a02e0e2 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -147,8 +147,8 @@ public: std::vector & unpacked_path ) const { // SimpleLogger().Write(logDEBUG) << "packed_path.size: " << packed_path.size(); - const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.startPhantom.forward_node_id); - const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.targetPhantom.forward_node_id); + const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.source_phantom.forward_node_id); + const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.target_phantom.forward_node_id); const unsigned packed_path_size = packed_path.size(); std::stack > recursion_stack; @@ -232,7 +232,7 @@ public: std::vector id_vector; facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id), id_vector); - const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position - 1 : phantom_node_pair.startPhantom.fwd_segment_position ) : 0 ); + const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1 : phantom_node_pair.source_phantom.fwd_segment_position ) : 0 ); const int end_index = id_vector.size(); BOOST_ASSERT( start_index >= 0 ); @@ -256,40 +256,40 @@ public: } } } - if(SPECIAL_EDGEID != phantom_node_pair.targetPhantom.packed_geometry_id ) { - // SimpleLogger().Write(logDEBUG) << "unpacking last segment " << phantom_node_pair.targetPhantom.packed_geometry_id; + if(SPECIAL_EDGEID != phantom_node_pair.target_phantom.packed_geometry_id ) { + // SimpleLogger().Write(logDEBUG) << "unpacking last segment " << phantom_node_pair.target_phantom.packed_geometry_id; // SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << (start_traversed_in_reverse ? "y" : "n"); // SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.startPhantom.fwd_segment_position: " << phantom_node_pair.startPhantom.fwd_segment_position << ", " << - // "phantom_node_pair.targetPhantom.fwd_segment_position: " << phantom_node_pair.targetPhantom.fwd_segment_position; + // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.source_phantom.fwd_segment_position: " << phantom_node_pair.source_phantom.fwd_segment_position << ", " << + // "phantom_node_pair.target_phantom.fwd_segment_position: " << phantom_node_pair.target_phantom.fwd_segment_position; std::vector id_vector; - facade->GetUncompressedGeometry(phantom_node_pair.targetPhantom.packed_geometry_id, id_vector); + facade->GetUncompressedGeometry(phantom_node_pair.target_phantom.packed_geometry_id, id_vector); if( target_traversed_in_reverse ) { std::reverse(id_vector.begin(), id_vector.end() ); } // SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); // SimpleLogger().Write(logDEBUG) << "unpacked_path.empty()=" << (unpacked_path.empty() ? "y" : "n"); - const bool is_local_path = (phantom_node_pair.startPhantom.packed_geometry_id == phantom_node_pair.targetPhantom.packed_geometry_id) && unpacked_path.empty(); - // SimpleLogger().Write(logDEBUG) << "is_local_path: " << (is_local_path ? "y" : "n"); + const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id == phantom_node_pair.target_phantom.packed_geometry_id) && unpacked_path.empty(); + // SimpleLogger().Write(logDEBUG) << "is_loc_pl_path: " << (is_local_path ? "y" : "n"); int start_index = 0; - int end_index = phantom_node_pair.targetPhantom.fwd_segment_position; + int end_index = phantom_node_pair.target_phantom.fwd_segment_position; // SimpleLogger().Write(logDEBUG) << "case1"; if (target_traversed_in_reverse) { - end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position; + end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position; } if (is_local_path) { // SimpleLogger().Write(logDEBUG) << "case3"; - start_index = phantom_node_pair.startPhantom.fwd_segment_position; - end_index = phantom_node_pair.targetPhantom.fwd_segment_position; + start_index = phantom_node_pair.source_phantom.fwd_segment_position; + end_index = phantom_node_pair.target_phantom.fwd_segment_position; if (target_traversed_in_reverse) { // SimpleLogger().Write(logDEBUG) << "case4"; - start_index = id_vector.size() - phantom_node_pair.startPhantom.fwd_segment_position; - end_index = id_vector.size() - phantom_node_pair.targetPhantom.fwd_segment_position; + start_index = id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position; + end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position; } } @@ -309,7 +309,7 @@ public: unpacked_path.push_back( PathData( id_vector[i], - phantom_node_pair.targetPhantom.name_id, + phantom_node_pair.target_phantom.name_id, TurnInstructionsClass::NoTurn, 0 ) diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 2dbcea798..e76493335 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -48,14 +48,15 @@ public: ) : super(facade), engine_working_data(engine_working_data) - {} + { } - ~ShortestPathRouting() {} + ~ShortestPathRouting() { } void operator()( const std::vector & phantom_nodes_vector, RawRouteData & raw_route_data - ) const { + ) const + { BOOST_FOREACH( const PhantomNodes & phantom_node_pair, phantom_nodes_vector @@ -108,61 +109,61 @@ public: //insert new starting nodes into forward heap, adjusted by previous distances. if( search_from_1st_node && - phantom_node_pair.startPhantom.forward_node_id != SPECIAL_NODEID + phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.forward_node_id << ", w: " << -phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( - phantom_node_pair.startPhantom.forward_node_id, - distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.startPhantom.forward_node_id + phantom_node_pair.source_phantom.forward_node_id, + distance1-phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), + phantom_node_pair.source_phantom.forward_node_id ); forward_heap2.Insert( - phantom_node_pair.startPhantom.forward_node_id, - distance1-phantom_node_pair.startPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.startPhantom.forward_node_id + phantom_node_pair.source_phantom.forward_node_id, + distance1-phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), + phantom_node_pair.source_phantom.forward_node_id ); } if( search_from_2nd_node && - phantom_node_pair.startPhantom.reverse_node_id != SPECIAL_NODEID + phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.startPhantom.reverse_node_id << ", w: " << -phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( - phantom_node_pair.startPhantom.reverse_node_id, - distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), - phantom_node_pair.startPhantom.reverse_node_id + phantom_node_pair.source_phantom.reverse_node_id, + distance2-phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), + phantom_node_pair.source_phantom.reverse_node_id ); forward_heap2.Insert( - phantom_node_pair.startPhantom.reverse_node_id, - distance2-phantom_node_pair.startPhantom.GetReverseWeightPlusOffset(), - phantom_node_pair.startPhantom.reverse_node_id + phantom_node_pair.source_phantom.reverse_node_id, + distance2-phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), + phantom_node_pair.source_phantom.reverse_node_id ); } //insert new backward nodes into backward heap, unadjusted. - if( phantom_node_pair.targetPhantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.forward_node_id << ", w: " << phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(); + if( phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( - phantom_node_pair.targetPhantom.forward_node_id, - phantom_node_pair.targetPhantom.GetForwardWeightPlusOffset(), - phantom_node_pair.targetPhantom.forward_node_id + phantom_node_pair.target_phantom.forward_node_id, + phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(), + phantom_node_pair.target_phantom.forward_node_id ); } - if( phantom_node_pair.targetPhantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.targetPhantom.reverse_node_id << ", w: " << phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(); + if( phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID ) { + SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); reverse_heap2.Insert( - phantom_node_pair.targetPhantom.reverse_node_id, - phantom_node_pair.targetPhantom.GetReverseWeightPlusOffset(), - phantom_node_pair.targetPhantom.reverse_node_id + phantom_node_pair.target_phantom.reverse_node_id, + phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(), + phantom_node_pair.target_phantom.reverse_node_id ); } const int forward_offset = super::ComputeEdgeOffset( - phantom_node_pair.startPhantom + phantom_node_pair.source_phantom ); const int reverse_offset = super::ComputeEdgeOffset( - phantom_node_pair.targetPhantom + phantom_node_pair.target_phantom ); //run two-Target Dijkstra routing step. @@ -348,11 +349,11 @@ public: if( (packed_legs1[current_leg].back() == packed_legs2[current_leg].back()) && - phantom_node_pair.targetPhantom.isBidirected() + phantom_node_pair.target_phantom.isBidirected() ) { const NodeID last_node_id = packed_legs2[current_leg].back(); - search_from_1st_node &= !(last_node_id == phantom_node_pair.targetPhantom.reverse_node_id); - search_from_2nd_node &= !(last_node_id == phantom_node_pair.targetPhantom.forward_node_id); + search_from_1st_node &= !(last_node_id == phantom_node_pair.target_phantom.reverse_node_id); + search_from_2nd_node &= !(last_node_id == phantom_node_pair.target_phantom.forward_node_id); BOOST_ASSERT( search_from_1st_node != search_from_2nd_node ); } @@ -365,7 +366,7 @@ public: std::swap( packed_legs1, packed_legs2 ); } raw_route_data.unpacked_path_segments.resize( packed_legs1.size() ); - // const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().startPhantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().startPhantom.fwd_segment_position; + // const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().source_phantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().source_phantom.fwd_segment_position; for(unsigned i = 0; i < packed_legs1.size(); ++i){ BOOST_ASSERT( !phantom_nodes_vector.empty() ); @@ -376,14 +377,14 @@ public: PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i]; // if (!at_beginning) // { - // unpack_phantom_node_pair.startPhantom.packed_geometry_id = SPECIAL_EDGEID; - // unpack_phantom_node_pair.startPhantom.fwd_segment_position = 0; + // unpack_phantom_node_pair.source_phantom.packed_geometry_id = SPECIAL_EDGEID; + // unpack_phantom_node_pair.source_phantom.fwd_segment_position = 0; // } // if (!at_end) // { - // unpack_phantom_node_pair.targetPhantom.packed_geometry_id = SPECIAL_EDGEID; - // unpack_phantom_node_pair.targetPhantom.fwd_segment_position = 0; + // unpack_phantom_node_pair.target_phantom.packed_geometry_id = SPECIAL_EDGEID; + // unpack_phantom_node_pair.target_phantom.fwd_segment_position = 0; // } super::UnpackPath( From 44077cb00785c8940270e470b59b9a51e5a0f83a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Mar 2014 15:14:39 +0100 Subject: [PATCH 41/89] refactor and streamline use of TurnInstructionsClass members --- Contractor/EdgeBasedGraphFactory.cpp | 22 +++---- DataStructures/TurnInstructions.h | 2 - Descriptors/DescriptionFactory.h | 4 +- Descriptors/JSONDescriptor.h | 82 ++++++++++++++------------ Server/DataStructures/SharedDataType.h | 60 +++++++++---------- 5 files changed, 87 insertions(+), 83 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 680f8ce2a..89cf6d63b 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -826,7 +826,7 @@ void EdgeBasedGraphFactory::Run( } const int turn_penalty = GetTurnPenalty(u, v, w, lua_state); TurnInstruction turn_instruction = AnalyzeTurn(u, v, w); - if(turn_instruction == TurnInstructions.UTurn){ + if(turn_instruction == TurnInstructionsClass::UTurn){ distance += speed_profile.uTurnPenalty; } distance += turn_penalty; @@ -934,7 +934,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( const NodeID w ) const { if(u == w) { - return TurnInstructions.UTurn; + return TurnInstructionsClass::UTurn; } const EdgeIterator edge1 = m_node_based_graph->FindEdge(u, v); @@ -944,10 +944,10 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( const EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2); if(!data1.contraFlow && data2.contraFlow) { - return TurnInstructions.EnterAgainstAllowedDirection; + return TurnInstructionsClass::EnterAgainstAllowedDirection; } if(data1.contraFlow && !data2.contraFlow) { - return TurnInstructions.LeaveAgainstAllowedDirection; + return TurnInstructionsClass::LeaveAgainstAllowedDirection; } //roundabouts need to be handled explicitely @@ -955,19 +955,19 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( //Is a turn possible? If yes, we stay on the roundabout! if( 1 == m_node_based_graph->GetOutDegree(v) ) { //No turn possible. - return TurnInstructions.NoTurn; + return TurnInstructionsClass::NoTurn; } - return TurnInstructions.StayOnRoundAbout; + return TurnInstructionsClass::StayOnRoundAbout; } //Does turn start or end on roundabout? if(data1.roundabout || data2.roundabout) { //We are entering the roundabout if( (!data1.roundabout) && data2.roundabout) { - return TurnInstructions.EnterRoundAbout; + return TurnInstructionsClass::EnterRoundAbout; } //We are leaving the roundabout if(data1.roundabout && (!data2.roundabout) ) { - return TurnInstructions.LeaveRoundAbout; + return TurnInstructionsClass::LeaveRoundAbout; } } @@ -977,9 +977,9 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( //TODO: Here we should also do a small graph exploration to check for // more complex situations if( 0 != data1.nameID ) { - return TurnInstructions.NoTurn; + return TurnInstructionsClass::NoTurn; } else if (m_node_based_graph->GetOutDegree(v) <= 2) { - return TurnInstructions.NoTurn; + return TurnInstructionsClass::NoTurn; } } @@ -988,7 +988,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( m_node_info_list[v], m_node_info_list[w] ); - return TurnInstructions.GetTurnDirectionOfInstruction(angle); + return TurnInstructionsClass::GetTurnDirectionOfInstruction(angle); } unsigned EdgeBasedGraphFactory::GetNumberOfEdgeBasedNodes() const { diff --git a/DataStructures/TurnInstructions.h b/DataStructures/TurnInstructions.h index 4a80ccfc2..cb60a32f5 100644 --- a/DataStructures/TurnInstructions.h +++ b/DataStructures/TurnInstructions.h @@ -92,6 +92,4 @@ struct TurnInstructionsClass : boost::noncopyable { }; -static TurnInstructionsClass TurnInstructions; - #endif /* TURNINSTRUCTIONS_H_ */ diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 12d0213b2..3b3a8432e 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -179,7 +179,7 @@ public: if(pathDescription.size() > 2){ pathDescription.pop_back(); pathDescription.back().necessary = true; - pathDescription.back().turn_instruction = TurnInstructions.NoTurn; + pathDescription.back().turn_instruction = TurnInstructionsClass::NoTurn; target_phantom.name_id = (pathDescription.end()-2)->name_id; } } else { @@ -188,7 +188,7 @@ public: if(std::numeric_limits::epsilon() > pathDescription[0].length) { if(pathDescription.size() > 2) { pathDescription.erase(pathDescription.begin()); - pathDescription[0].turn_instruction = TurnInstructions.HeadOn; + pathDescription[0].turn_instruction = TurnInstructionsClass::HeadOn; pathDescription[0].necessary = true; start_phantom.name_id = pathDescription[0].name_id; } diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 5415cc5ed..cd5cebc99 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -44,6 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. template class JSONDescriptor : public BaseDescriptor { private: + // TODO: initalize in c'tor DataFacadeT * facade; DescriptorConfig config; DescriptionFactory description_factory; @@ -59,7 +60,7 @@ private: int start_index; int name_id; int leave_at_exit; - } roundAbout; + } round_about; struct Segment { Segment() : name_id(-1), length(-1), position(-1) {} @@ -419,56 +420,61 @@ public: //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.leave_at_exit = 0; - roundAbout.name_id = 0; - std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction; + unsigned necessary_segments_running_index = 0; + round_about.leave_at_exit = 0; + round_about.name_id = 0; + std::string temp_dist, temp_length, temp_duration, temp_bearing, temp_instruction; + //Fetch data from Factory and generate a string from it. BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) { - TurnInstruction current_instruction = segment.turn_instruction & TurnInstructions.InverseAccessRestrictionFlag; + TurnInstruction current_instruction = segment.turn_instruction & TurnInstructionsClass::InverseAccessRestrictionFlag; entered_restricted_area_count += (current_instruction != segment.turn_instruction); - if(TurnInstructions.TurnIsNecessary( current_instruction) ) { - if(TurnInstructions.EnterRoundAbout == current_instruction) { - roundAbout.name_id = segment.name_id; - roundAbout.start_index = prefixSumOfNecessarySegments; - } else { - if(0 != prefixSumOfNecessarySegments){ + if (TurnInstructionsClass::TurnIsNecessary( current_instruction) ) + { + if (TurnInstructionsClass::EnterRoundAbout == current_instruction) + { + round_about.name_id = segment.name_id; + round_about.start_index = necessary_segments_running_index; + } + else + { + if (0 != necessary_segments_running_index) + { reply.content.push_back(","); } reply.content.push_back("[\""); - if(TurnInstructions.LeaveRoundAbout == current_instruction) { - intToString(TurnInstructions.EnterRoundAbout, tmpInstruction); - reply.content.push_back(tmpInstruction); + if(TurnInstructionsClass::LeaveRoundAbout == current_instruction) { + intToString(TurnInstructionsClass::EnterRoundAbout, temp_instruction); + reply.content.push_back(temp_instruction); reply.content.push_back("-"); - intToString(roundAbout.leave_at_exit+1, tmpInstruction); - reply.content.push_back(tmpInstruction); - roundAbout.leave_at_exit = 0; + intToString(round_about.leave_at_exit+1, temp_instruction); + reply.content.push_back(temp_instruction); + round_about.leave_at_exit = 0; } else { - intToString(current_instruction, tmpInstruction); - reply.content.push_back(tmpInstruction); + intToString(current_instruction, temp_instruction); + reply.content.push_back(temp_instruction); } reply.content.push_back("\",\""); reply.content.push_back(facade->GetEscapedNameForNameID(segment.name_id)); reply.content.push_back("\","); - intToString(segment.length, tmpDist); - reply.content.push_back(tmpDist); + intToString(segment.length, temp_dist); + reply.content.push_back(temp_dist); reply.content.push_back(","); - intToString(prefixSumOfNecessarySegments, tmpLength); - reply.content.push_back(tmpLength); + intToString(necessary_segments_running_index, temp_length); + reply.content.push_back(temp_length); reply.content.push_back(","); - intToString(segment.duration/10, tmpDuration); - reply.content.push_back(tmpDuration); + intToString(segment.duration/10, temp_duration); + reply.content.push_back(temp_duration); reply.content.push_back(",\""); - intToString(segment.length, tmpLength); - reply.content.push_back(tmpLength); + intToString(segment.length, temp_length); + reply.content.push_back(temp_length); reply.content.push_back("m\",\""); double bearing_value = round(segment.bearing/10.); reply.content.push_back(Azimuth::Get(bearing_value)); reply.content.push_back("\","); - intToString(bearing_value, tmpBearing); - reply.content.push_back(tmpBearing); + intToString(bearing_value, temp_bearing); + reply.content.push_back(temp_bearing); reply.content.push_back("]"); route_segments_list.push_back( @@ -479,22 +485,22 @@ public: ) ); } - } else if(TurnInstructions.StayOnRoundAbout == current_instruction) { - ++roundAbout.leave_at_exit; + } else if(TurnInstructionsClass::StayOnRoundAbout == current_instruction) { + ++round_about.leave_at_exit; } if(segment.necessary) - ++prefixSumOfNecessarySegments; + ++necessary_segments_running_index; } if(INT_MAX != route_length) { reply.content.push_back(",[\""); - intToString(TurnInstructions.ReachedYourDestination, tmpInstruction); - reply.content.push_back(tmpInstruction); + intToString(TurnInstructionsClass::ReachedYourDestination, temp_instruction); + reply.content.push_back(temp_instruction); reply.content.push_back("\",\""); reply.content.push_back("\","); reply.content.push_back("0"); reply.content.push_back(","); - intToString(prefixSumOfNecessarySegments-1, tmpLength); - reply.content.push_back(tmpLength); + intToString(necessary_segments_running_index-1, temp_length); + reply.content.push_back(temp_length); reply.content.push_back(","); reply.content.push_back("0"); reply.content.push_back(",\""); diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index b7154094f..49cfac0a4 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -96,17 +96,17 @@ struct SharedDataLayout { uint64_t GetSizeOfLayout() const { uint64_t result = - (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)) + - (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) + + (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) ) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + + (r_search_tree_size * sizeof(RTreeNode) ) + + sizeof(checksum) + 1024*sizeof(char); return result; } @@ -184,29 +184,29 @@ struct SharedDataLayout { } uint64_t GetRSearchTreeOffset() const { uint64_t result = - (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)) + - (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + - (timestamp_length * sizeof(char) ) + - (coordinate_list_size * sizeof(FixedPointCoordinate)) + - (turn_instruction_list_size * sizeof(TurnInstructions) ); + (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) ) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)); return result; } uint64_t GetChecksumOffset() const { uint64_t result = - (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)) + - (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) ); + (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) ) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + + (r_search_tree_size * sizeof(RTreeNode) ); return result; } }; From 549bcb502b3e09b8881caad652fcde866ca61aa8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 26 Mar 2014 15:28:50 +0100 Subject: [PATCH 42/89] minor renaming efforts --- Descriptors/DescriptionFactory.h | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 3b3a8432e..d06cf58f9 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -105,13 +105,16 @@ public: /** starts at index 1 */ pathDescription[0].length = 0; - for(unsigned i = 1; i < pathDescription.size(); ++i) { + for(unsigned i = 1; i < pathDescription.size(); ++i) + { pathDescription[i].length = FixedPointCoordinate::ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); } - // std::string string0 = facade->GetEscapedNameForNameID(pathDescription[0].name_id); - // std::string string1; - + for (unsigned i = 0; i < pathDescription.size(); ++i) + { + const std::string name = facade->GetEscapedNameForNameID(pathDescription[0].name_id); + SimpleLogger().Write(logDEBUG) << "[" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location; + } /*Simplify turn instructions Input : @@ -154,23 +157,23 @@ public: // string0 = string1; // } - double lengthOfSegment = 0; - unsigned durationOfSegment = 0; - unsigned indexOfSegmentBegin = 0; + double segment_length = 0.; + unsigned segment_duration = 0; + unsigned segment_start_index = 0; 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; + segment_length += pathDescription[i].length; + segment_duration += pathDescription[i].duration; + pathDescription[segment_start_index].length = segment_length; + pathDescription[segment_start_index].duration = segment_duration; if(TurnInstructionsClass::NoTurn != pathDescription[i].turn_instruction) { BOOST_ASSERT(pathDescription[i].necessary); - lengthOfSegment = 0; - durationOfSegment = 0; - indexOfSegmentBegin = i; + segment_length = 0; + segment_duration = 0; + segment_start_index = i; } } @@ -183,7 +186,7 @@ public: target_phantom.name_id = (pathDescription.end()-2)->name_id; } } else { - pathDescription[indexOfSegmentBegin].duration *= (1.-target_phantom.ratio); + pathDescription[segment_start_index].duration *= (1.-target_phantom.ratio); } if(std::numeric_limits::epsilon() > pathDescription[0].length) { if(pathDescription.size() > 2) { From 752fb880be74d194e7e72fc7e5b0139ed9d3307c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 28 Mar 2014 17:13:00 +0100 Subject: [PATCH 43/89] switch edge-expanded street name indexes to be first segment names (18 failed tests left) --- Contractor/EdgeBasedGraphFactory.cpp | 19 +++-- DataStructures/PhantomNodes.h | 12 ++- DataStructures/RawRouteData.h | 11 ++- DataStructures/StaticRTree.h | 6 +- Descriptors/DescriptionFactory.cpp | 80 +++++++++++------- Descriptors/DescriptionFactory.h | 14 ++-- Descriptors/JSONDescriptor.h | 94 ++++++++++++++++++++-- RoutingAlgorithms/AlternativePathRouting.h | 11 ++- RoutingAlgorithms/BasicRoutingInterface.h | 19 +++-- RoutingAlgorithms/ShortestPathRouting.h | 13 ++- 10 files changed, 202 insertions(+), 77 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 89cf6d63b..dfa6c30a3 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -318,14 +318,6 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e1) == m_geometry_compressor.HasEntryForID(e2) ); if( m_geometry_compressor.HasEntryForID(e1) ) { - if(forward_data.edgeBasedNodeID == 16176) { - SimpleLogger().Write(logDEBUG) << "reverse_data.edgeBasedNodeID=" << reverse_data.edgeBasedNodeID; - SimpleLogger().Write(logDEBUG) << "u: " << u << ", v: " << v << " at " << m_node_info_list.at(u).lat/COORDINATE_PRECISION << "," - << m_node_info_list.at(u).lon/COORDINATE_PRECISION << "<->" << m_node_info_list.at(v).lat/COORDINATE_PRECISION << "," - << m_node_info_list.at(v).lon/COORDINATE_PRECISION; - SimpleLogger().Write(logDEBUG) << "pos(" << e1 << ")=" << m_geometry_compressor.GetPositionForID(e1); - SimpleLogger().Write(logDEBUG) << "pos(" << e2 << ")=" << m_geometry_compressor.GetPositionForID(e2); - } BOOST_ASSERT( m_geometry_compressor.HasEntryForID(e2) ); @@ -605,6 +597,7 @@ void EdgeBasedGraphFactory::Run( forward_weight1 + (add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty :0), forward_weight2 ); + SimpleLogger().Write(logDEBUG) << "compressing fwd segment with name " << m_node_based_graph->GetEdgeData(forward_e1).nameID; m_geometry_compressor.CompressEdge( reverse_e1, reverse_e2, @@ -613,8 +606,14 @@ void EdgeBasedGraphFactory::Run( reverse_weight1 , reverse_weight2 + (add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty :0) ); - + SimpleLogger().Write(logDEBUG) << "compressing rev segment with name " << m_node_based_graph->GetEdgeData(reverse_e1).nameID; ++removed_node_count; + + BOOST_ASSERT + ( + m_node_based_graph->GetEdgeData(forward_e1).nameID == + m_node_based_graph->GetEdgeData(reverse_e1).nameID + ); } } SimpleLogger().Write() << "removed " << removed_node_count << " nodes"; @@ -840,7 +839,7 @@ void EdgeBasedGraphFactory::Run( original_edge_data_vector.push_back( OriginalEdgeData( (edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v), - edge_data2.nameID, + (edge_is_compressed ? edge_data1.nameID : edge_data1.nameID), turn_instruction, edge_is_compressed ) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 5396c3e60..4aeead635 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -42,7 +42,6 @@ struct PhantomNode { forward_offset(0), reverse_offset(0), packed_geometry_id(SPECIAL_EDGEID), - ratio(0.), fwd_segment_position(0) { } @@ -54,11 +53,10 @@ struct PhantomNode { int forward_offset; int reverse_offset; unsigned packed_geometry_id; - double ratio; + // double ratio; FixedPointCoordinate location; unsigned short fwd_segment_position; - int GetForwardWeightPlusOffset() const { SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight; @@ -79,7 +77,7 @@ struct PhantomNode { reverse_weight = INVALID_EDGE_WEIGHT; forward_offset = 0; reverse_offset = 0; - ratio = 0.; + // ratio = 0.; location.Reset(); } @@ -106,8 +104,8 @@ struct PhantomNode { (forward_weight != INVALID_EDGE_WEIGHT) || (reverse_weight != INVALID_EDGE_WEIGHT) ) && - (ratio >= 0.) && - (ratio <= 1.) && + // (ratio >= 0.) && + // (ratio <= 1.) && (name_id != std::numeric_limits::max() ); } @@ -162,7 +160,7 @@ inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn) { "rev-w: " << pn.reverse_weight << ", " << "fwd-o: " << pn.forward_offset << ", " << "rev-o: " << pn.reverse_offset << ", " << - "ratio: " << pn.ratio << ", " << + // "ratio: " << pn.ratio << ", " << "geom: " << pn.packed_geometry_id << ", " << "pos: " << pn.fwd_segment_position << ", " << "loc: " << pn.location; diff --git a/DataStructures/RawRouteData.h b/DataStructures/RawRouteData.h index 509c4ca97..cedbc2d76 100644 --- a/DataStructures/RawRouteData.h +++ b/DataStructures/RawRouteData.h @@ -70,10 +70,19 @@ struct RawRouteData { unsigned checkSum; int lengthOfShortestPath; int lengthOfAlternativePath; + bool source_traversed_in_reverse; + bool target_traversed_in_reverse; + bool alt_source_traversed_in_reverse; + bool alt_target_traversed_in_reverse; + RawRouteData() : checkSum(UINT_MAX), lengthOfShortestPath(INT_MAX), - lengthOfAlternativePath(INT_MAX) + lengthOfAlternativePath(INT_MAX), + source_traversed_in_reverse(false), + target_traversed_in_reverse(false), + alt_source_traversed_in_reverse(false), + alt_target_traversed_in_reverse(false) { } }; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 738564547..699603617 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -771,12 +771,12 @@ public: { result_phantom_node.reverse_weight *= 1.-ratio; } - result_phantom_node.ratio = ratio; + // result_phantom_node.ratio = ratio; SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; - SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight << ", ratio: " << result_phantom_node.ratio; - SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset << ", ratio: " << result_phantom_node.ratio; + SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight;// << ", ratio: " << result_phantom_node.ratio; + SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset;// << ", ratio: " << result_phantom_node.ratio; SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id; SimpleLogger().Write(logDEBUG) << "geom id: " << result_phantom_node.packed_geometry_id; diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 2b2842282..9e84e3be8 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -31,18 +31,18 @@ DescriptionFactory::DescriptionFactory() : entireLength(0) { } DescriptionFactory::~DescriptionFactory() { } -inline double DescriptionFactory::DegreeToRadian(const double degree) const { - return degree * (M_PI/180); +inline double DescriptionFactory::DegreeToRadian(const double degree) const +{ + return degree * (M_PI/180.); } -inline double DescriptionFactory::RadianToDegree(const double radian) const { - return radian * (180/M_PI); +inline double DescriptionFactory::RadianToDegree(const double radian) const +{ + return radian * (180./M_PI); } -double DescriptionFactory::GetBearing( - const FixedPointCoordinate & A, - const FixedPointCoordinate & B -) const { +double DescriptionFactory::GetBearing(const FixedPointCoordinate & A, const FixedPointCoordinate & B) const +{ double delta_long = DegreeToRadian(B.lon/COORDINATE_PRECISION - A.lon/COORDINATE_PRECISION); const double lat1 = DegreeToRadian(A.lat/COORDINATE_PRECISION); @@ -51,24 +51,42 @@ double DescriptionFactory::GetBearing( const double y = sin(delta_long) * cos(lat2); const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long); double result = RadianToDegree(atan2(y, x)); - while(result < 0.) { + while (result < 0.) + { result += 360.; } - while(result >= 360.) { + + while (result >= 360.) + { result -= 360.; } return result; } -void DescriptionFactory::SetStartSegment(const PhantomNode & start) { - start_phantom = start; +void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool source_traversed_in_reverse) +{ + int fwd_weight = source.forward_weight; + int rev_weight = source.reverse_weight; + int fwd_offset = source.forward_offset; + int rev_offset = source.reverse_offset; + SimpleLogger().Write(logDEBUG) << "df source, traversed in reverse: " << (source_traversed_in_reverse ? "y" : "n") << ", location: " << source.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + SimpleLogger().Write(logDEBUG) << "duration of first segment: " << (source_traversed_in_reverse ? source.GetReverseWeightPlusOffset() : source.GetForwardWeightPlusOffset()); + start_phantom = source; AppendSegment( - start.location, - PathData(0, start.name_id, 10, start.forward_weight) + source.location, + PathData(0, source.name_id, 10, source.forward_weight) ); } -void DescriptionFactory::SetEndSegment(const PhantomNode & target) { +void DescriptionFactory::SetEndSegment(const PhantomNode & target, const bool target_traversed_in_reverse) +{ + int fwd_weight = target.forward_weight; + int rev_weight = target.reverse_weight; + int fwd_offset = target.forward_offset; + int rev_offset = target.reverse_offset; + SimpleLogger().Write(logDEBUG) << "df target, traversed in reverse: " << (target_traversed_in_reverse ? "y" : "n") << ", location: " << target.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + SimpleLogger().Write(logDEBUG) << "duration of last segment: " << (target_traversed_in_reverse ? target.GetReverseWeightPlusOffset() : target.GetForwardWeightPlusOffset()); + target_phantom = target; pathDescription.push_back( SegmentInformation( @@ -86,22 +104,22 @@ void DescriptionFactory::AppendSegment( const FixedPointCoordinate & coordinate, const PathData & data ) { - if( - ( 1 == pathDescription.size()) && - ( pathDescription.back().location == coordinate) - ) { - pathDescription.back().name_id = data.name_id; - } else { - pathDescription.push_back( - SegmentInformation( - coordinate, - data.name_id, - data.durationOfSegment, - 0, - data.turnInstruction - ) - ); - } + // if( + // ( 1 == pathDescription.size()) && + // ( pathDescription.back().location == coordinate) + // ) { + // pathDescription.back().name_id = data.name_id; + // } else { + pathDescription.push_back( + SegmentInformation( + coordinate, + data.name_id, + data.durationOfSegment, + 0, + data.turnInstruction + ) + ); + // } } void DescriptionFactory::AppendEncodedPolylineString( diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index d06cf58f9..e011b2cd2 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -87,8 +87,8 @@ public: void AppendUnencodedPolylineString(std::vector &output) const; void AppendSegment(const FixedPointCoordinate & coordinate, const PathData & data); void BuildRouteSummary(const double distance, const unsigned time); - void SetStartSegment(const PhantomNode & start_phantom); - void SetEndSegment(const PhantomNode & start_phantom); + void SetStartSegment(const PhantomNode & start_phantom, const bool source_traversed_in_reverse); + void SetEndSegment(const PhantomNode & start_phantom, const bool target_traversed_in_reverse); void AppendEncodedPolylineString( const bool return_encoded, std::vector & output @@ -105,15 +105,17 @@ public: /** starts at index 1 */ pathDescription[0].length = 0; - for(unsigned i = 1; i < pathDescription.size(); ++i) + for (unsigned i = 1; i < pathDescription.size(); ++i) { + //move down names by one, q&d hack + pathDescription[i-1].name_id = pathDescription[i].name_id; pathDescription[i].length = FixedPointCoordinate::ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); } for (unsigned i = 0; i < pathDescription.size(); ++i) { const std::string name = facade->GetEscapedNameForNameID(pathDescription[0].name_id); - SimpleLogger().Write(logDEBUG) << "[" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location; + SimpleLogger().Write(logDEBUG) << "df [" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location; } /*Simplify turn instructions @@ -186,7 +188,7 @@ public: target_phantom.name_id = (pathDescription.end()-2)->name_id; } } else { - pathDescription[segment_start_index].duration *= (1.-target_phantom.ratio); + // pathDescription[segment_start_index].duration *= (1.-target_phantom.ratio); } if(std::numeric_limits::epsilon() > pathDescription[0].length) { if(pathDescription.size() > 2) { @@ -196,7 +198,7 @@ public: start_phantom.name_id = pathDescription[0].name_id; } } else { - pathDescription[0].duration *= start_phantom.ratio; + // pathDescription[0].duration *= start_phantom.ratio; } //Generalize poly line diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index cd5cebc99..ba3f84594 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -99,7 +99,7 @@ public: FixedPointCoordinate current_coordinate; BOOST_FOREACH(const PathData & path_data, route_leg) { current_coordinate = facade->GetCoordinateOfNode(path_data.node); - description_factory.AppendSegment(current_coordinate, path_data ); + description_factory.AppendSegment(current_coordinate, path_data); ++added_element_count; } // description_factory.SetEndSegment( leg_phantoms.target_phantom ); @@ -120,7 +120,8 @@ public: "{\"status\":" ); - if(INT_MAX == raw_route.lengthOfShortestPath) { + if (INVALID_EDGE_WEIGHT == raw_route.lengthOfShortestPath) + { //We do not need to do much, if there is no route ;-) reply.content.push_back( "207,\"status_message\": \"Cannot find route between points\"}" @@ -128,12 +129,87 @@ public: return; } - description_factory.SetStartSegment(phantom_nodes.source_phantom); + std::string name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); + int fwd_weight = phantom_nodes.source_phantom.forward_weight; + int rev_weight = phantom_nodes.source_phantom.reverse_weight; + int fwd_offset = phantom_nodes.source_phantom.forward_offset; + int rev_offset = phantom_nodes.source_phantom.reverse_offset; + SimpleLogger().Write(logDEBUG) << "json source: " << name << ", location: " << phantom_nodes.source_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); + fwd_weight = phantom_nodes.target_phantom.forward_weight; + rev_weight = phantom_nodes.target_phantom.reverse_weight; + fwd_offset = phantom_nodes.target_phantom.forward_offset; + rev_offset = phantom_nodes.target_phantom.reverse_offset; + SimpleLogger().Write(logDEBUG) << "json target: " << name << ", location: " << phantom_nodes.target_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + + + //TODO: replace the previous logic with this one. + + //check if first segment is non-zero + std::string road_name; + int source_duration = phantom_nodes.source_phantom.GetForwardWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "-> source_traversed_in_reverse: " << (raw_route.source_traversed_in_reverse ? "y" : "n"); + if (!raw_route.source_traversed_in_reverse) + { + source_duration = phantom_nodes.source_phantom.GetReverseWeightPlusOffset(); + } + BOOST_ASSERT(source_duration >= 0); + road_name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); + if (source_duration > 0) + { + SimpleLogger().Write(logDEBUG) << "adding source \"" << road_name << "\" at " << phantom_nodes.source_phantom.location << ", duration: " << source_duration; + } + else + { + SimpleLogger().Write(logDEBUG) << "ignoring source \"" << road_name << "\""; + } + + // TODO, for each unpacked segment add the leg to the description + BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() ); + + for (unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i) + { + const std::vector & leg_path = raw_route.unpacked_path_segments[i]; + const PhantomNodes & leg_phantoms = raw_route.segmentEndCoordinates[i]; + SimpleLogger().Write(logDEBUG) << " Describing leg from " << leg_phantoms.source_phantom.location << " and " << leg_phantoms.target_phantom.location; + FixedPointCoordinate current_coordinate; + BOOST_FOREACH(const PathData & path_data, leg_path) + { + current_coordinate = facade->GetCoordinateOfNode(path_data.node); + road_name = facade->GetEscapedNameForNameID(path_data.name_id); + SimpleLogger().Write(logDEBUG) << " adding way point for \"" << road_name << "\" at " << current_coordinate << ", duration: " << path_data.durationOfSegment; + } + } + + //check if last segment is non-zero + road_name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); + + int target_duration = phantom_nodes.target_phantom.GetForwardWeightPlusOffset(); + if (raw_route.target_traversed_in_reverse) + { + target_duration = phantom_nodes.target_phantom.GetReverseWeightPlusOffset(); + } + BOOST_ASSERT(target_duration >= 0); + + if (target_duration > 0) + { + SimpleLogger().Write(logDEBUG) << "adding target \"" << road_name << "\" at " << phantom_nodes.target_phantom.location << ", duration: " << target_duration; + } + else + { + SimpleLogger().Write(logDEBUG) << "ignoring target \"" << road_name << "\""; + } + SimpleLogger().Write(logDEBUG) << "-> target_traversed_in_reverse: " << (raw_route.target_traversed_in_reverse ? "y" : "n"); + + //END OF TODO + + description_factory.SetStartSegment(phantom_nodes.source_phantom, raw_route.source_traversed_in_reverse); reply.content.push_back("0," "\"status_message\": \"Found route between points\","); BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() ); - for( unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i ) { + for (unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i) + { const int added_segments = DescribeLeg( raw_route.unpacked_path_segments[i], raw_route.segmentEndCoordinates[i] @@ -143,7 +219,7 @@ public: added_segments + shortest_leg_end_indices.back() ); } - description_factory.SetEndSegment(phantom_nodes.target_phantom); + description_factory.SetEndSegment(phantom_nodes.target_phantom, raw_route.target_traversed_in_reverse); description_factory.Run(facade, config.zoom_level); reply.content.push_back("\"route_geometry\": "); @@ -195,14 +271,16 @@ public: //only one alternative route is computed at this time, so this is hardcoded - if(raw_route.lengthOfAlternativePath != INT_MAX) { - alternate_descriptionFactory.SetStartSegment(phantom_nodes.source_phantom); + + if(raw_route.lengthOfAlternativePath != INVALID_EDGE_WEIGHT) + { + alternate_descriptionFactory.SetStartSegment(phantom_nodes.source_phantom, raw_route.alt_source_traversed_in_reverse); //Get all the coordinates for the computed route BOOST_FOREACH(const PathData & path_data, raw_route.unpacked_alternative) { current = facade->GetCoordinateOfNode(path_data.node); alternate_descriptionFactory.AppendSegment(current, path_data ); } - alternate_descriptionFactory.SetEndSegment(phantom_nodes.target_phantom); + alternate_descriptionFactory.SetEndSegment(phantom_nodes.target_phantom, raw_route.alt_target_traversed_in_reverse); } alternate_descriptionFactory.Run(facade, config.zoom_level); diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 589bbb393..c7571403f 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -316,8 +316,9 @@ public: } //Unpack shortest path and alternative, if they exist - if( INVALID_EDGE_WEIGHT != upper_bound_to_shortest_path_distance ) { - BOOST_ASSERT( !packed_shortest_path.empty() ); + if( INVALID_EDGE_WEIGHT != upper_bound_to_shortest_path_distance ) + { + BOOST_ASSERT(!packed_shortest_path.empty()); raw_route_data.unpacked_path_segments.resize(1); // SimpleLogger().Write() << "fwd offset1: " << phantom_node_pair.source_phantom.fwd_segment_position; // SimpleLogger().Write() << "fwd offset2: " << phantom_node_pair.source_phantom.rev_segment_position; @@ -332,6 +333,9 @@ public: // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.target_phantom.packed_geometry_id: " << phantom_node_pair.target_phantom.packed_geometry_id; // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); + raw_route_data.source_traversed_in_reverse = (packed_shortest_path.front() != phantom_node_pair.source_phantom.forward_node_id); + raw_route_data.target_traversed_in_reverse = (packed_shortest_path.back() != phantom_node_pair.target_phantom.forward_node_id); + super::UnpackPath( // -- packed input packed_shortest_path, @@ -357,6 +361,9 @@ public: packed_alternate_path ); + raw_route_data.source_traversed_in_reverse = (packed_alternate_path.front() != phantom_node_pair.source_phantom.forward_node_id); + raw_route_data.target_traversed_in_reverse = (packed_alternate_path.back() != phantom_node_pair.target_phantom.forward_node_id); + // unpack the alternate path super::UnpackPath( packed_alternate_path, diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 69a02e0e2..bd793d58f 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -186,6 +186,7 @@ public: } } if( SPECIAL_EDGEID == smaller_edge_id ){ + SimpleLogger().Write() << "checking reverse"; for( EdgeID edge_id = facade->BeginEdges(edge.second); edge_id < facade->EndEdges(edge.second); @@ -234,6 +235,9 @@ public: const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1 : phantom_node_pair.source_phantom.fwd_segment_position ) : 0 ); const int end_index = id_vector.size(); + std::string name = facade->GetEscapedNameForNameID(name_index); + SimpleLogger().Write(logDEBUG) << "compressed via segment " << name << " from [" << start_index << "," << end_index << "]"; + BOOST_ASSERT( start_index >= 0 ); BOOST_ASSERT( start_index <= end_index ); @@ -293,7 +297,7 @@ public: } } - // SimpleLogger().Write(logDEBUG) << "fetching from [" << start_index << "," << end_index << "]"; + SimpleLogger().Write(logDEBUG) << "fetching target segment from [" << start_index << "," << end_index << "]"; BOOST_ASSERT( start_index >= 0 ); for( @@ -302,10 +306,10 @@ public: ( start_index < end_index ? ++i :--i) ) { BOOST_ASSERT( i >= -1 ); - // if ( i >= 0 ) - // { - // SimpleLogger().Write(logDEBUG) << "[" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); - // } + if ( i >= 0 ) + { + SimpleLogger().Write(logDEBUG) << "target [" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); + } unpacked_path.push_back( PathData( id_vector[i], @@ -316,6 +320,11 @@ public: ); } } + BOOST_FOREACH(const PathData & path_data, unpacked_path) + { + std::string name = facade->GetEscapedNameForNameID(path_data.name_id); + SimpleLogger().Write(logDEBUG) << "{up} " << facade->GetCoordinateOfNode(path_data.node) << ", name: " << name; + } } inline void UnpackEdge( diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index e76493335..8372d89e3 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -362,17 +362,22 @@ public: ++current_leg; } - if( distance1 > distance2 ) { + if (distance1 > distance2) + { std::swap( packed_legs1, packed_legs2 ); } raw_route_data.unpacked_path_segments.resize( packed_legs1.size() ); // const int start_offset = ( packed_legs1[0].front() == phantom_nodes_vector.front().source_phantom.forward_node_id ? 1 : -1 )*phantom_nodes_vector.front().source_phantom.fwd_segment_position; - for(unsigned i = 0; i < packed_legs1.size(); ++i){ - BOOST_ASSERT( !phantom_nodes_vector.empty() ); + raw_route_data.source_traversed_in_reverse = (packed_legs1.front().front() != phantom_nodes_vector.front().source_phantom.forward_node_id); + raw_route_data.target_traversed_in_reverse = (packed_legs1.back().back() != phantom_nodes_vector.back().target_phantom.forward_node_id); + + for (unsigned i = 0; i < packed_legs1.size(); ++i) + { + BOOST_ASSERT(!phantom_nodes_vector.empty()); // const bool at_beginning = (packed_legs1[i] == packed_legs1.front()); // const bool at_end = (packed_legs1[i] == packed_legs1.back()); - BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size() ); + BOOST_ASSERT(packed_legs1.size() == raw_route_data.unpacked_path_segments.size()); PhantomNodes unpack_phantom_node_pair = phantom_nodes_vector[i]; // if (!at_beginning) From 0b89a9d55493bb7a3533ff9fe7892a02bb52f127 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 28 Mar 2014 18:25:35 +0100 Subject: [PATCH 44/89] ignore last edge-expanded segment if it spans over to undistinguishable node-based nodes (down to 9 failed) --- RoutingAlgorithms/BasicRoutingInterface.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index bd793d58f..bd23bf37a 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -323,7 +323,28 @@ public: BOOST_FOREACH(const PathData & path_data, unpacked_path) { std::string name = facade->GetEscapedNameForNameID(path_data.name_id); - SimpleLogger().Write(logDEBUG) << "{up} " << facade->GetCoordinateOfNode(path_data.node) << ", name: " << name; + SimpleLogger().Write(logDEBUG) << "{up} node: " << path_data.node << ", " << facade->GetCoordinateOfNode(path_data.node) << ", name: " << name; + } + + // there is no equivalent to a node-based node in an edge-expanded graph. + // two equivalent routes may start (or end) at different node-based edges + // as they are added with the offset how much "distance" on the edge + // has already been traversed. Depending on offset one needs to remove + // the last node. + if (unpacked_path.size() > 1) + { + const unsigned last_index = unpacked_path.size()-1; + const unsigned second_to_last_index = last_index -1; + + //looks like a trivially true check but tests for underflow + BOOST_ASSERT(last_index > second_to_last_index); + + if (unpacked_path[last_index].node == unpacked_path[second_to_last_index].node) + { + SimpleLogger().Write(logDEBUG) << "{rm} node: " << unpacked_path.back().node; + unpacked_path.pop_back(); + } + BOOST_ASSERT(!unpacked_path.empty()); } } From 9ccc8a7404f7d6b3b392a015a1b3c6a13a857073 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Apr 2014 16:13:54 +0200 Subject: [PATCH 45/89] remove first segment if distance is 0 (down to 7 failed) --- Descriptors/DescriptionFactory.cpp | 35 +++++++++++++----------------- Descriptors/DescriptionFactory.h | 4 ---- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 9e84e3be8..2b8b41a71 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -60,6 +60,9 @@ double DescriptionFactory::GetBearing(const FixedPointCoordinate & A, const Fixe { result -= 360.; } + + SimpleLogger().Write(logDEBUG) << "bearing between " << A << " and " << B << " is " << result; + return result; } @@ -100,26 +103,18 @@ void DescriptionFactory::SetEndSegment(const PhantomNode & target, const bool ta ); } -void DescriptionFactory::AppendSegment( - const FixedPointCoordinate & coordinate, - const PathData & data -) { - // if( - // ( 1 == pathDescription.size()) && - // ( pathDescription.back().location == coordinate) - // ) { - // pathDescription.back().name_id = data.name_id; - // } else { - pathDescription.push_back( - SegmentInformation( - coordinate, - data.name_id, - data.durationOfSegment, - 0, - data.turnInstruction - ) - ); - // } +void DescriptionFactory::AppendSegment(const FixedPointCoordinate & coordinate, const PathData & path_point) +{ + if ((1 == pathDescription.size()) && ( pathDescription.back().location == coordinate)) + { + pathDescription.back().name_id = path_point.name_id; + } + else + { + pathDescription.push_back( + SegmentInformation(coordinate, path_point.name_id, path_point.durationOfSegment, 0, path_point.turnInstruction) + ); + } } void DescriptionFactory::AppendEncodedPolylineString( diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index e011b2cd2..08e1cfb87 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -187,8 +187,6 @@ public: pathDescription.back().turn_instruction = TurnInstructionsClass::NoTurn; target_phantom.name_id = (pathDescription.end()-2)->name_id; } - } else { - // pathDescription[segment_start_index].duration *= (1.-target_phantom.ratio); } if(std::numeric_limits::epsilon() > pathDescription[0].length) { if(pathDescription.size() > 2) { @@ -197,8 +195,6 @@ public: pathDescription[0].necessary = true; start_phantom.name_id = pathDescription[0].name_id; } - } else { - // pathDescription[0].duration *= start_phantom.ratio; } //Generalize poly line From 8ae467985f8613adf3183ec68c4d4b4fd79611a0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 1 Apr 2014 17:05:19 +0200 Subject: [PATCH 46/89] turn off colored logging if output is redirected to file --- Util/SimpleLogger.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 144ca73b7..00b893579 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -32,6 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + #include #include @@ -70,16 +72,20 @@ private: bool m_is_mute; }; -class SimpleLogger { +class SimpleLogger +{ public: SimpleLogger() : level(logINFO) { } - std::ostringstream& Write(LogLevel l = logINFO) { - try { + std::ostringstream& Write(LogLevel l = logINFO) + { + try + { boost::mutex::scoped_lock lock(logger_mutex); level = l; os << "["; - switch(level) { + switch(level) + { case logINFO: os << "info"; break; @@ -96,22 +102,26 @@ public: break; } os << "] "; - } catch (...) { } + } + catch (...) { } return os; } virtual ~SimpleLogger() { - if(!LogPolicy::GetInstance().IsMute()) { - switch(level) { + if(!LogPolicy::GetInstance().IsMute()) + { + const bool is_terminal = isatty(fileno(stdout)); + switch(level) + { case logINFO: - std::cout << os.str() << std::endl; + std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl; break; case logWARNING: - std::cerr << RED << os.str() << COL_RESET << std::endl; + std::cerr << (is_terminal ? RED : "") << os.str() << (is_terminal ? COL_RESET : "") << std::endl; break; case logDEBUG: #ifndef NDEBUG - std::cout << YELLOW << os.str() << COL_RESET << std::endl; + std::cout << (is_terminal ? YELLOW : "") << os.str() << (is_terminal ? COL_RESET : "") << std::endl; #endif break; default: From 899ab9ddc042973ea4f19121eeead062d35f1e24 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 2 Apr 2014 11:20:14 +0200 Subject: [PATCH 47/89] remove some uncommented code --- DataStructures/PhantomNodes.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 4aeead635..bb8fa267b 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -32,7 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/SimpleLogger.h" #include "../typedefs.h" -struct PhantomNode { +struct PhantomNode +{ PhantomNode() : forward_node_id(SPECIAL_NODEID), reverse_node_id(SPECIAL_NODEID), @@ -53,7 +54,6 @@ struct PhantomNode { int forward_offset; int reverse_offset; unsigned packed_geometry_id; - // double ratio; FixedPointCoordinate location; unsigned short fwd_segment_position; @@ -77,7 +77,6 @@ struct PhantomNode { reverse_weight = INVALID_EDGE_WEIGHT; forward_offset = 0; reverse_offset = 0; - // ratio = 0.; location.Reset(); } @@ -118,9 +117,9 @@ struct PhantomNode { struct PhantomNodes { - //TODO: rename to lower-case non-camel source_*,target_* PhantomNode source_phantom; PhantomNode target_phantom; + void Reset() { source_phantom.Reset(); @@ -144,15 +143,15 @@ struct PhantomNodes } }; -inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) { - // out << "Node1: " << pn.source_phantom.forward_node_id << "\n"; - // out << "Node2: " << pn.target_phantom.reverse_node_id << "\n"; +inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) +{ out << "source_coord: " << pn.source_phantom.location << "\n"; out << "target_coord: " << pn.target_phantom.location << std::endl; return out; } -inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn) { +inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn) +{ out << "node1: " << pn.forward_node_id << ", " << "node2: " << pn.reverse_node_id << ", " << "name: " << pn.name_id << ", " << @@ -160,7 +159,6 @@ inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn) { "rev-w: " << pn.reverse_weight << ", " << "fwd-o: " << pn.forward_offset << ", " << "rev-o: " << pn.reverse_offset << ", " << - // "ratio: " << pn.ratio << ", " << "geom: " << pn.packed_geometry_id << ", " << "pos: " << pn.fwd_segment_position << ", " << "loc: " << pn.location; From 394e369b547ae94cee2f78cbe07b9472ff9f728a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 8 Apr 2014 19:47:52 -0400 Subject: [PATCH 48/89] fix edge-expanded offsets --- Contractor/GeometryCompressor.cpp | 2 +- DataStructures/PhantomNodes.h | 47 +++++++++++++-- DataStructures/StaticRTree.h | 12 ++-- Descriptors/DescriptionFactory.cpp | 10 ++-- Descriptors/DescriptionFactory.h | 2 +- Descriptors/JSONDescriptor.h | 46 +++++++-------- RoutingAlgorithms/AlternativePathRouting.h | 69 +++++++++++----------- RoutingAlgorithms/BasicRoutingInterface.h | 61 ++++++++++--------- RoutingAlgorithms/ShortestPathRouting.h | 14 +++-- 9 files changed, 153 insertions(+), 110 deletions(-) diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 9691a6f44..c2b7c16d8 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -81,7 +81,7 @@ void GeometryCompressor::SerializeInternalVector(const std::string & path) const // write indices array unsigned prefix_sum_of_list_indices = 0; - for(unsigned i = 0; i < m_compressed_geometries.size(); ++i ) + for (unsigned i = 0; i < m_compressed_geometries.size(); ++i) { geometry_out_stream.write( (char*)&prefix_sum_of_list_indices, diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index bb8fa267b..e7389474d 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -59,14 +59,26 @@ struct PhantomNode int GetForwardWeightPlusOffset() const { - SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight; - return reverse_offset + forward_weight; + if (SPECIAL_NODEID == forward_node_id) + { + return 0; + } + // SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight; + const int result = (forward_offset + forward_weight); + // SimpleLogger().Write(logDEBUG) << "forward queue weight: " << result; + return result; } int GetReverseWeightPlusOffset() const { - SimpleLogger().Write(logDEBUG) << "->rev_offset: " << reverse_offset << ", weight: " << reverse_weight; - return forward_offset + reverse_weight; + if (SPECIAL_NODEID == reverse_node_id) + { + return 0; + } + // SimpleLogger().Write(logDEBUG) << "->rev_offset: " << reverse_offset << ", weight: " << reverse_weight; + const int result = (reverse_offset + reverse_weight); + // SimpleLogger().Write(logDEBUG) << "reverse queue weight: " << result; + return result; } void Reset() @@ -103,8 +115,6 @@ struct PhantomNode (forward_weight != INVALID_EDGE_WEIGHT) || (reverse_weight != INVALID_EDGE_WEIGHT) ) && - // (ratio >= 0.) && - // (ratio <= 1.) && (name_id != std::numeric_limits::max() ); } @@ -141,6 +151,31 @@ struct PhantomNodes { return source_phantom == target_phantom; } + + bool ComputeForwardQueueOffset() const + { + if (source_phantom.forward_node_id == target_phantom.forward_node_id) + { + const int forward_queue_weight = source_phantom.GetForwardWeightPlusOffset(); + const int reverse_queue_weight = target_phantom.GetForwardWeightPlusOffset(); + const int weight_diff = (forward_queue_weight - reverse_queue_weight); + SimpleLogger().Write(logDEBUG) << "fwd queue offset: " << std::max(0, weight_diff); + return 0;//std::max(0, weight_diff); + } + return 0; + } + + bool ComputeReverseQueueOffset() const + { + if (source_phantom.reverse_node_id == target_phantom.reverse_node_id) + { + const int forward_queue_weight = source_phantom.GetReverseWeightPlusOffset(); + const int reverse_queue_weight = target_phantom.GetReverseWeightPlusOffset(); + const int weight_diff = (forward_queue_weight - reverse_queue_weight); + return 0;//std::max(0, weight_diff); + } + return 0; + } }; inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 699603617..9047d5b7b 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -765,21 +765,21 @@ public: if (SPECIAL_NODEID != result_phantom_node.forward_node_id) { - result_phantom_node.forward_weight *= (ratio); + result_phantom_node.forward_weight *= ratio; } - if( SPECIAL_NODEID != result_phantom_node.reverse_node_id ) + if (SPECIAL_NODEID != result_phantom_node.reverse_node_id) { - result_phantom_node.reverse_weight *= 1.-ratio; + result_phantom_node.reverse_weight *= (1.-ratio); } - // result_phantom_node.ratio = ratio; SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; - SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight;// << ", ratio: " << result_phantom_node.ratio; - SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset;// << ", ratio: " << result_phantom_node.ratio; + SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight; + SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset; SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id; SimpleLogger().Write(logDEBUG) << "geom id: " << result_phantom_node.packed_geometry_id; + SimpleLogger().Write(logDEBUG) << "ratio: " << ratio; return found_a_nearest_edge; } diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 2b8b41a71..45cc584da 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -61,7 +61,7 @@ double DescriptionFactory::GetBearing(const FixedPointCoordinate & A, const Fixe result -= 360.; } - SimpleLogger().Write(logDEBUG) << "bearing between " << A << " and " << B << " is " << result; + // SimpleLogger().Write(logDEBUG) << "bearing between " << A << " and " << B << " is " << result; return result; } @@ -72,8 +72,8 @@ void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool int rev_weight = source.reverse_weight; int fwd_offset = source.forward_offset; int rev_offset = source.reverse_offset; - SimpleLogger().Write(logDEBUG) << "df source, traversed in reverse: " << (source_traversed_in_reverse ? "y" : "n") << ", location: " << source.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - SimpleLogger().Write(logDEBUG) << "duration of first segment: " << (source_traversed_in_reverse ? source.GetReverseWeightPlusOffset() : source.GetForwardWeightPlusOffset()); + // SimpleLogger().Write(logDEBUG) << "df source, traversed in reverse: " << (source_traversed_in_reverse ? "y" : "n") << ", location: " << source.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + // SimpleLogger().Write(logDEBUG) << "duration of first segment: " << (source_traversed_in_reverse ? source.GetReverseWeightPlusOffset() : source.GetForwardWeightPlusOffset()); start_phantom = source; AppendSegment( source.location, @@ -87,8 +87,8 @@ void DescriptionFactory::SetEndSegment(const PhantomNode & target, const bool ta int rev_weight = target.reverse_weight; int fwd_offset = target.forward_offset; int rev_offset = target.reverse_offset; - SimpleLogger().Write(logDEBUG) << "df target, traversed in reverse: " << (target_traversed_in_reverse ? "y" : "n") << ", location: " << target.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - SimpleLogger().Write(logDEBUG) << "duration of last segment: " << (target_traversed_in_reverse ? target.GetReverseWeightPlusOffset() : target.GetForwardWeightPlusOffset()); + // SimpleLogger().Write(logDEBUG) << "df target, traversed in reverse: " << (target_traversed_in_reverse ? "y" : "n") << ", location: " << target.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + // SimpleLogger().Write(logDEBUG) << "duration of last segment: " << (target_traversed_in_reverse ? target.GetReverseWeightPlusOffset() : target.GetForwardWeightPlusOffset()); target_phantom = target; pathDescription.push_back( diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 08e1cfb87..3d5f49bb6 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -115,7 +115,7 @@ public: for (unsigned i = 0; i < pathDescription.size(); ++i) { const std::string name = facade->GetEscapedNameForNameID(pathDescription[0].name_id); - SimpleLogger().Write(logDEBUG) << "df [" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location; + // SimpleLogger().Write(logDEBUG) << "df [" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location; } /*Simplify turn instructions diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index ba3f84594..559e8e2db 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -134,13 +134,13 @@ public: int rev_weight = phantom_nodes.source_phantom.reverse_weight; int fwd_offset = phantom_nodes.source_phantom.forward_offset; int rev_offset = phantom_nodes.source_phantom.reverse_offset; - SimpleLogger().Write(logDEBUG) << "json source: " << name << ", location: " << phantom_nodes.source_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + // SimpleLogger().Write(logDEBUG) << "json source: " << name << ", location: " << phantom_nodes.source_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); fwd_weight = phantom_nodes.target_phantom.forward_weight; rev_weight = phantom_nodes.target_phantom.reverse_weight; fwd_offset = phantom_nodes.target_phantom.forward_offset; rev_offset = phantom_nodes.target_phantom.reverse_offset; - SimpleLogger().Write(logDEBUG) << "json target: " << name << ", location: " << phantom_nodes.target_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; + // SimpleLogger().Write(logDEBUG) << "json target: " << name << ", location: " << phantom_nodes.target_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; //TODO: replace the previous logic with this one. @@ -148,21 +148,21 @@ public: //check if first segment is non-zero std::string road_name; int source_duration = phantom_nodes.source_phantom.GetForwardWeightPlusOffset(); - SimpleLogger().Write(logDEBUG) << "-> source_traversed_in_reverse: " << (raw_route.source_traversed_in_reverse ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "-> source_traversed_in_reverse: " << (raw_route.source_traversed_in_reverse ? "y" : "n"); if (!raw_route.source_traversed_in_reverse) { source_duration = phantom_nodes.source_phantom.GetReverseWeightPlusOffset(); } BOOST_ASSERT(source_duration >= 0); road_name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); - if (source_duration > 0) - { - SimpleLogger().Write(logDEBUG) << "adding source \"" << road_name << "\" at " << phantom_nodes.source_phantom.location << ", duration: " << source_duration; - } - else - { - SimpleLogger().Write(logDEBUG) << "ignoring source \"" << road_name << "\""; - } + // if (source_duration > 0) + // { + // SimpleLogger().Write(logDEBUG) << "adding source \"" << road_name << "\" at " << phantom_nodes.source_phantom.location << ", duration: " << source_duration; + // } + // else + // { + // SimpleLogger().Write(logDEBUG) << "ignoring source \"" << road_name << "\""; + // } // TODO, for each unpacked segment add the leg to the description BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() ); @@ -170,14 +170,14 @@ public: for (unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i) { const std::vector & leg_path = raw_route.unpacked_path_segments[i]; - const PhantomNodes & leg_phantoms = raw_route.segmentEndCoordinates[i]; - SimpleLogger().Write(logDEBUG) << " Describing leg from " << leg_phantoms.source_phantom.location << " and " << leg_phantoms.target_phantom.location; + // const PhantomNodes & leg_phantoms = raw_route.segmentEndCoordinates[i]; + // SimpleLogger().Write(logDEBUG) << " Describing leg from " << leg_phantoms.source_phantom.location << " and " << leg_phantoms.target_phantom.location; FixedPointCoordinate current_coordinate; BOOST_FOREACH(const PathData & path_data, leg_path) { current_coordinate = facade->GetCoordinateOfNode(path_data.node); road_name = facade->GetEscapedNameForNameID(path_data.name_id); - SimpleLogger().Write(logDEBUG) << " adding way point for \"" << road_name << "\" at " << current_coordinate << ", duration: " << path_data.durationOfSegment; + // SimpleLogger().Write(logDEBUG) << " adding way point for \"" << road_name << "\" at " << current_coordinate << ", duration: " << path_data.durationOfSegment; } } @@ -191,15 +191,15 @@ public: } BOOST_ASSERT(target_duration >= 0); - if (target_duration > 0) - { - SimpleLogger().Write(logDEBUG) << "adding target \"" << road_name << "\" at " << phantom_nodes.target_phantom.location << ", duration: " << target_duration; - } - else - { - SimpleLogger().Write(logDEBUG) << "ignoring target \"" << road_name << "\""; - } - SimpleLogger().Write(logDEBUG) << "-> target_traversed_in_reverse: " << (raw_route.target_traversed_in_reverse ? "y" : "n"); + // if (target_duration > 0) + // { + // SimpleLogger().Write(logDEBUG) << "adding target \"" << road_name << "\" at " << phantom_nodes.target_phantom.location << ", duration: " << target_duration; + // } + // else + // { + // SimpleLogger().Write(logDEBUG) << "ignoring target \"" << road_name << "\""; + // } + // SimpleLogger().Write(logDEBUG) << "-> target_traversed_in_reverse: " << (raw_route.target_traversed_in_reverse ? "y" : "n"); //END OF TODO diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index c7571403f..acadc9a44 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -49,21 +49,18 @@ class AlternativeRouting : private BasicRoutingInterface { typedef SearchEngineData::QueryHeap QueryHeap; typedef std::pair SearchSpaceEdge; - struct RankedCandidateNode { - RankedCandidateNode( - const NodeID node, - const int length, - const int sharing - ) : - node(node), - length(length), - sharing(sharing) + struct RankedCandidateNode + { + RankedCandidateNode(const NodeID node, const int length, const int sharing) + : node(node), length(length), sharing(sharing) { } NodeID node; int length; int sharing; - bool operator<(const RankedCandidateNode& other) const { + + bool operator<(const RankedCandidateNode& other) const + { return (2*length + sharing) < (2*other.length + other.sharing); } }; @@ -92,7 +89,7 @@ public: ) { // raw_route_data.lengthOfShortestPath = INVALID_EDGE_WEIGHT; // raw_route_data.lengthOfAlternativePath = INVALID_EDGE_WEIGHT; - SimpleLogger().Write(logDEBUG) << "not executing path search"; + // SimpleLogger().Write(logDEBUG) << "not executing path search"; return; } @@ -120,7 +117,7 @@ public: int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT; NodeID middle_node = SPECIAL_NODEID; if(phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "fwd-a insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.source_phantom.forward_node_id, -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), @@ -128,7 +125,7 @@ public: ); } if(phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "fwd-b insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.source_phantom.reverse_node_id, -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), @@ -137,7 +134,7 @@ public: } if(phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "rev-a insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.target_phantom.forward_node_id, phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(), @@ -145,7 +142,7 @@ public: ); } if(phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); + SimpleLogger().Write(logDEBUG) << "rev-b insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.target_phantom.reverse_node_id, phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(), @@ -153,14 +150,16 @@ public: ); } - const int forward_offset = super::ComputeEdgeOffset( - phantom_node_pair.source_phantom - ); - const int reverse_offset = super::ComputeEdgeOffset( - phantom_node_pair.target_phantom - ); + const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); + // const int forward_offset = super::ComputeEdgeOffset( + // phantom_node_pair.source_phantom + // ); + const int reverse_offset = phantom_node_pair.ComputeReverseQueueOffset(); + // const int reverse_offset = super::ComputeEdgeOffset( + // phantom_node_pair.target_phantom + // ); - SimpleLogger().Write(logDEBUG) << "fwd_offset: " << forward_offset << ", reverse_offset: " << reverse_offset; + // SimpleLogger().Write(logDEBUG) << "fwd_offset: " << forward_offset << ", reverse_offset: " << reverse_offset; //search from s and t till new_min/(1+epsilon) > length_of_shortest_path while(0 < (forward_heap1.Size() + reverse_heap1.Size())){ @@ -188,9 +187,9 @@ public: } } - SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; + // SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; sort_unique_resize( via_node_candidate_list ); - SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; + // SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; std::vector packed_forward_path; std::vector packed_reverse_path; @@ -208,7 +207,7 @@ public: //TODO: leave early when no path found: - SimpleLogger().Write(logDEBUG) << "ub: " << upper_bound_to_shortest_path_distance; + // SimpleLogger().Write(logDEBUG) << "ub: " << upper_bound_to_shortest_path_distance; boost::unordered_map approximated_forward_sharing; boost::unordered_map approximated_reverse_sharing; @@ -251,8 +250,8 @@ public: } } - SimpleLogger().Write(logDEBUG) << "fwd_search_space size: " << forward_search_space.size() << ", marked " << approximated_forward_sharing.size() << " nodes"; - SimpleLogger().Write(logDEBUG) << "rev_search_space size: " << reverse_search_space.size() << ", marked " << approximated_reverse_sharing.size() << " nodes"; + // SimpleLogger().Write(logDEBUG) << "fwd_search_space size: " << forward_search_space.size() << ", marked " << approximated_forward_sharing.size() << " nodes"; + // SimpleLogger().Write(logDEBUG) << "rev_search_space size: " << reverse_search_space.size() << ", marked " << approximated_reverse_sharing.size() << " nodes"; std::vector preselected_node_list; BOOST_FOREACH(const NodeID node, via_node_candidate_list) { @@ -272,7 +271,7 @@ public: } } - SimpleLogger().Write() << preselected_node_list.size() << " passed preselection"; + // SimpleLogger().Write() << preselected_node_list.size() << " passed preselection"; std::vector & packed_shortest_path = packed_forward_path; std::reverse(packed_shortest_path.begin(), packed_shortest_path.end()); @@ -345,7 +344,7 @@ public: raw_route_data.unpacked_path_segments.front() ); raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; - SimpleLogger().Write(logDEBUG) << "upper_bound_to_shortest_path_distance: " << upper_bound_to_shortest_path_distance; + // SimpleLogger().Write(logDEBUG) << "upper_bound_to_shortest_path_distance: " << upper_bound_to_shortest_path_distance; } if( SPECIAL_NODEID != selected_via_node ) { @@ -372,7 +371,7 @@ public: ); raw_route_data.lengthOfAlternativePath = length_of_via_path; - SimpleLogger().Write(logDEBUG) << "length_of_via_path: " << length_of_via_path; + // SimpleLogger().Write(logDEBUG) << "length_of_via_path: " << length_of_via_path; } } @@ -635,7 +634,7 @@ private: ) const { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); - const int scaled_distance = (distance-edge_expansion_offset)/(1.+VIAPATH_EPSILON); + const int scaled_distance = distance/(1.+VIAPATH_EPSILON); // SimpleLogger().Write(logDEBUG) << "node: " << node << ", distance: " << distance << ", ub: " << *upper_bound_to_shortest_path_distance << ", scaled_distance: " << scaled_distance; if( (INVALID_EDGE_WEIGHT != *upper_bound_to_shortest_path_distance) && @@ -650,12 +649,14 @@ private: std::make_pair(forward_heap.GetData( node ).parent, node) ); - if( reverse_heap.WasInserted(node) ) { + if (reverse_heap.WasInserted(node)) { search_space_intersection.push_back(node); const int new_distance = reverse_heap.GetKey(node) + distance; - if( new_distance < *upper_bound_to_shortest_path_distance ){ - if( new_distance >= 0 ) { + if (new_distance < *upper_bound_to_shortest_path_distance) + { + if ((new_distance + edge_expansion_offset) >= 0) + { *middle_node = node; *upper_bound_to_shortest_path_distance = new_distance; } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index bd23bf37a..4071734c7 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -64,22 +64,27 @@ public: int * upper_bound, const int edge_expansion_offset, const bool forward_direction - ) const { + ) const + { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); // SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; - if(reverse_heap.WasInserted(node) ){ + if (reverse_heap.WasInserted(node)) + { const int new_distance = reverse_heap.GetKey(node) + distance; // SimpleLogger().Write(logDEBUG) << "new_distance: " << new_distance; - if(new_distance < *upper_bound ){ - if( new_distance >= 0 ) { + if(new_distance < *upper_bound ) + { + if( new_distance + edge_expansion_offset >= 0 ) + { *middle_node_id = node; *upper_bound = new_distance; } } } - if( (distance-edge_expansion_offset) > *upper_bound ){ + if (distance > *upper_bound) + { // SimpleLogger().Write() << "found path"; forward_heap.DeleteAll(); return; @@ -186,7 +191,7 @@ public: } } if( SPECIAL_EDGEID == smaller_edge_id ){ - SimpleLogger().Write() << "checking reverse"; + // SimpleLogger().Write() << "checking reverse"; for( EdgeID edge_id = facade->BeginEdges(edge.second); edge_id < facade->EndEdges(edge.second); @@ -236,7 +241,7 @@ public: const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1 : phantom_node_pair.source_phantom.fwd_segment_position ) : 0 ); const int end_index = id_vector.size(); std::string name = facade->GetEscapedNameForNameID(name_index); - SimpleLogger().Write(logDEBUG) << "compressed via segment " << name << " from [" << start_index << "," << end_index << "]"; + // SimpleLogger().Write(logDEBUG) << "compressed via segment " << name << " from [" << start_index << "," << end_index << "]"; BOOST_ASSERT( start_index >= 0 ); @@ -297,7 +302,7 @@ public: } } - SimpleLogger().Write(logDEBUG) << "fetching target segment from [" << start_index << "," << end_index << "]"; + // SimpleLogger().Write(logDEBUG) << "fetching target segment from [" << start_index << "," << end_index << "]"; BOOST_ASSERT( start_index >= 0 ); for( @@ -308,7 +313,7 @@ public: BOOST_ASSERT( i >= -1 ); if ( i >= 0 ) { - SimpleLogger().Write(logDEBUG) << "target [" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); + // SimpleLogger().Write(logDEBUG) << "target [" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); } unpacked_path.push_back( PathData( @@ -320,11 +325,11 @@ public: ); } } - BOOST_FOREACH(const PathData & path_data, unpacked_path) - { - std::string name = facade->GetEscapedNameForNameID(path_data.name_id); - SimpleLogger().Write(logDEBUG) << "{up} node: " << path_data.node << ", " << facade->GetCoordinateOfNode(path_data.node) << ", name: " << name; - } + // BOOST_FOREACH(const PathData & path_data, unpacked_path) + // { + // std::string name = facade->GetEscapedNameForNameID(path_data.name_id); + // SimpleLogger().Write(logDEBUG) << "{up} node: " << path_data.node << ", " << facade->GetCoordinateOfNode(path_data.node) << ", name: " << name; + // } // there is no equivalent to a node-based node in an edge-expanded graph. // two equivalent routes may start (or end) at different node-based edges @@ -341,7 +346,7 @@ public: if (unpacked_path[last_index].node == unpacked_path[second_to_last_index].node) { - SimpleLogger().Write(logDEBUG) << "{rm} node: " << unpacked_path.back().node; + // SimpleLogger().Write(logDEBUG) << "{rm} node: " << unpacked_path.back().node; unpacked_path.pop_back(); } BOOST_ASSERT(!unpacked_path.empty()); @@ -450,19 +455,19 @@ public: } } - int ComputeEdgeOffset(const PhantomNode & phantom_node) const { - int weight_offset = 0; - if (phantom_node.forward_node_id != SPECIAL_NODEID) - { - weight_offset += phantom_node.GetForwardWeightPlusOffset(); - } - if (phantom_node.reverse_node_id != SPECIAL_NODEID) - { - weight_offset += phantom_node.GetReverseWeightPlusOffset(); - } - return weight_offset; - // return phantom_node.forward_weight + (phantom_node.isBidirected() ? phantom_node.reverse_weight : 0); - } + // int ComputeOffset(const PhantomNode & phantom_node) const { + // int weight_offset = 0; + // if (phantom_node.forward_node_id != SPECIAL_NODEID) + // { + // weight_offset += phantom_node.GetForwardWeightPlusOffset(); + // } + // if (phantom_node.reverse_node_id != SPECIAL_NODEID) + // { + // weight_offset += phantom_node.GetReverseWeightPlusOffset(); + // } + // return weight_offset; + // // return phantom_node.forward_weight + (phantom_node.isBidirected() ? phantom_node.reverse_weight : 0); + // } }; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 8372d89e3..e605cec2e 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -159,12 +159,14 @@ public: ); } - const int forward_offset = super::ComputeEdgeOffset( - phantom_node_pair.source_phantom - ); - const int reverse_offset = super::ComputeEdgeOffset( - phantom_node_pair.target_phantom - ); + const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); + // const int forward_offset = super::ComputeForwardOffset( + // phantom_node_pair.source_phantom + // ); + const int reverse_offset = -phantom_node_pair.ComputeReverseQueueOffset(); + // const int reverse_offset = super::ComputeReverseOffset( + // phantom_node_pair.target_phantom + // ); //run two-Target Dijkstra routing step. while(0 < (forward_heap1.Size() + reverse_heap1.Size() )){ From 8ec3d549a6fb8a09756b72f13d4203e8c6555f04 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 9 Apr 2014 16:09:35 -0400 Subject: [PATCH 49/89] further fixes but forward/reverse edge weights are reversed --- Contractor/EdgeBasedGraphFactory.cpp | 2 +- DataStructures/PhantomNodes.h | 47 +++++++++++----------- DataStructures/StaticRTree.h | 12 +++--- RoutingAlgorithms/AlternativePathRouting.h | 12 +++--- RoutingAlgorithms/ShortestPathRouting.h | 12 +++--- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index dfa6c30a3..381ad0da6 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -545,7 +545,7 @@ void EdgeBasedGraphFactory::Run( continue; } - if ( + if ( //TODO: rename to IsCompatibleTo fwd_edge_data1.IsEqualTo(fwd_edge_data2) && rev_edge_data1.IsEqualTo(rev_edge_data2) ) { diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index e7389474d..04380d53a 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -152,30 +152,31 @@ struct PhantomNodes return source_phantom == target_phantom; } - bool ComputeForwardQueueOffset() const - { - if (source_phantom.forward_node_id == target_phantom.forward_node_id) - { - const int forward_queue_weight = source_phantom.GetForwardWeightPlusOffset(); - const int reverse_queue_weight = target_phantom.GetForwardWeightPlusOffset(); - const int weight_diff = (forward_queue_weight - reverse_queue_weight); - SimpleLogger().Write(logDEBUG) << "fwd queue offset: " << std::max(0, weight_diff); - return 0;//std::max(0, weight_diff); - } - return 0; - } + // bool ComputeForwardQueueOffset() const + // { + // if (source_phantom.forward_node_id == target_phantom.forward_node_id) + // { + // const int forward_queue_weight = source_phantom.GetForwardWeightPlusOffset(); + // const int reverse_queue_weight = target_phantom.GetForwardWeightPlusOffset(); + // const int weight_diff = (forward_queue_weight - reverse_queue_weight); + // SimpleLogger().Write(logDEBUG) << "fwd queue offset: " << std::max(0, weight_diff); + // return 0;//std::max(0, weight_diff); + // } + // return 0; + // } - bool ComputeReverseQueueOffset() const - { - if (source_phantom.reverse_node_id == target_phantom.reverse_node_id) - { - const int forward_queue_weight = source_phantom.GetReverseWeightPlusOffset(); - const int reverse_queue_weight = target_phantom.GetReverseWeightPlusOffset(); - const int weight_diff = (forward_queue_weight - reverse_queue_weight); - return 0;//std::max(0, weight_diff); - } - return 0; - } + // bool ComputeReverseQueueOffset() const + // { + // if (source_phantom.reverse_node_id == target_phantom.reverse_node_id) + // { + // const int forward_queue_weight = source_phantom.GetReverseWeightPlusOffset(); + // const int reverse_queue_weight = target_phantom.GetReverseWeightPlusOffset(); + // const int weight_diff = (forward_queue_weight - reverse_queue_weight); + // SimpleLogger().Write(logDEBUG) << "rev queue offset: " << std::max(0, weight_diff); + // return 0;//std::max(0, weight_diff); + // } + // return 0; + // } }; inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 9047d5b7b..b0594b199 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -691,13 +691,13 @@ public: ) { //found a new minimum min_dist = current_perpendicular_distance; //TODO: use assignment c'tor in PhantomNode - result_phantom_node.forward_node_id = current_edge.forward_edge_based_node_id; - result_phantom_node.reverse_node_id = current_edge.reverse_edge_based_node_id; + result_phantom_node.forward_node_id = current_edge.reverse_edge_based_node_id; + result_phantom_node.reverse_node_id = current_edge.forward_edge_based_node_id; 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.forward_weight = current_edge.reverse_weight; + result_phantom_node.reverse_weight = current_edge.forward_weight; + result_phantom_node.forward_offset = current_edge.reverse_offset; + result_phantom_node.reverse_offset = current_edge.forward_offset; result_phantom_node.packed_geometry_id = current_edge.packed_geometry_id; result_phantom_node.fwd_segment_position = current_edge.fwd_segment_position; diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index acadc9a44..b0ac3237f 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -150,11 +150,11 @@ public: ); } - const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); + // const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); // const int forward_offset = super::ComputeEdgeOffset( // phantom_node_pair.source_phantom // ); - const int reverse_offset = phantom_node_pair.ComputeReverseQueueOffset(); + // const int reverse_offset = phantom_node_pair.ComputeReverseQueueOffset(); // const int reverse_offset = super::ComputeEdgeOffset( // phantom_node_pair.target_phantom // ); @@ -171,7 +171,7 @@ public: &upper_bound_to_shortest_path_distance, via_node_candidate_list, forward_search_space, - forward_offset + 0 ); } if(0 < reverse_heap1.Size()){ @@ -182,7 +182,7 @@ public: &upper_bound_to_shortest_path_distance, via_node_candidate_list, reverse_search_space, - reverse_offset + 0 ); } } @@ -286,7 +286,7 @@ public: //prioritizing via nodes for deep inspection BOOST_FOREACH(const NodeID node, preselected_node_list) { int length_of_via_path = 0, sharing_of_via_path = 0; - ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path, forward_offset+reverse_offset, packed_shortest_path); + ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path, 0, packed_shortest_path); const int maximum_allowed_sharing = upper_bound_to_shortest_path_distance*VIAPATH_GAMMA; if( sharing_of_via_path <= maximum_allowed_sharing && length_of_via_path <= upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)) { ranked_candidates_list.push_back( @@ -307,7 +307,7 @@ public: int length_of_via_path = INVALID_EDGE_WEIGHT; NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID; BOOST_FOREACH(const RankedCandidateNode & candidate, ranked_candidates_list){ - if(ViaNodeCandidatePassesTTest(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate, forward_offset+reverse_offset, upper_bound_to_shortest_path_distance, &length_of_via_path, &s_v_middle, &v_t_middle)) { + if(ViaNodeCandidatePassesTTest(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate, 0, upper_bound_to_shortest_path_distance, &length_of_via_path, &s_v_middle, &v_t_middle)) { // select first admissable selected_via_node = candidate.node; break; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index e605cec2e..8eff2cbe3 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -159,11 +159,11 @@ public: ); } - const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); + // const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); // const int forward_offset = super::ComputeForwardOffset( // phantom_node_pair.source_phantom // ); - const int reverse_offset = -phantom_node_pair.ComputeReverseQueueOffset(); + // const int reverse_offset = -phantom_node_pair.ComputeReverseQueueOffset(); // const int reverse_offset = super::ComputeReverseOffset( // phantom_node_pair.target_phantom // ); @@ -176,7 +176,7 @@ public: reverse_heap1, &middle1, &local_upper_bound1, - forward_offset, + 0, true ); } @@ -186,7 +186,7 @@ public: forward_heap1, &middle1, &local_upper_bound1, - reverse_offset, + 0, false ); } @@ -200,7 +200,7 @@ public: reverse_heap2, &middle2, &local_upper_bound2, - forward_offset, + 0, true ); } @@ -210,7 +210,7 @@ public: forward_heap2, &middle2, &local_upper_bound2, - reverse_offset, + 0, false ); } From 5b8d8a83dd7e797a80a684ccdf92c12334388e2b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Apr 2014 16:39:11 -0400 Subject: [PATCH 50/89] fix mangled offsets and edge weights on compressed edges (all tests passing) --- Contractor/EdgeBasedGraphFactory.cpp | 46 +++++++++++++++++++------ Contractor/GeometryCompressor.cpp | 1 + Contractor/GeometryCompressor.h | 6 ---- DataStructures/StaticRTree.h | 38 ++++++++++---------- RoutingAlgorithms/ShortestPathRouting.h | 2 ++ 5 files changed, 58 insertions(+), 35 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 381ad0da6..6b6e4f255 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -352,25 +352,37 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( // reconstruct bidirectional edge with individual weights and put each into the NN index - std::vector forward_dist_prefix_sum( forward_geometry.size() ); - std::vector reverse_dist_prefix_sum( reverse_geometry.size() ); + std::vector forward_dist_prefix_sum(forward_geometry.size(), 0); + std::vector reverse_dist_prefix_sum(reverse_geometry.size(), 0); // quick'n'dirty prefix sum as std::partial_sum needs addtional casts // SimpleLogger().Write(logDEBUG) << "Prefix sums of edge " << e1 << ", w: " << reverse_data.distance; int temp_sum = 0; - for( unsigned i = 0; i < forward_geometry.size(); ++i ) { + + std::cout << "\nfwd geom: "; + for (unsigned i = 0; i < forward_geometry.size(); ++i) + { + forward_dist_prefix_sum[i] = temp_sum; temp_sum += forward_geometry[i].second; + BOOST_ASSERT( forward_data.distance >= temp_sum ); - forward_dist_prefix_sum[i] = forward_data.distance - temp_sum; + std::cout << forward_dist_prefix_sum[i] << " "; } + std::cout << std::endl; + // BOOST_ASSERT( forward_data.distance == temp_sum ); temp_sum = 0; + std::cout << "rev geom: "; for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { - temp_sum += reverse_geometry[i].second; - BOOST_ASSERT( reverse_data.distance >= temp_sum ); + temp_sum += reverse_geometry[reverse_geometry.size()-1-i].second; reverse_dist_prefix_sum[i] = reverse_data.distance - temp_sum; + BOOST_ASSERT( reverse_data.distance >= temp_sum ); + + std::cout << reverse_dist_prefix_sum[i] << " "; } - // BOOST_ASSERT( reverse_data.distance == temp_sum ); + std::cout << std::endl; + + // BOOST_ASSERT(false); BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); @@ -386,12 +398,18 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( { max_id = std::max(reverse_data.edgeBasedNodeID, max_id); } + + SimpleLogger().Write(logDEBUG) << "-> serializing packed edge " << forward_data.edgeBasedNodeID << "|" << reverse_data.edgeBasedNodeID; + // traverse arrays from start and end respectively for( unsigned i = 0; i < geometry_size; ++i ) { BOOST_ASSERT( current_edge_start_coordinate_id == reverse_geometry[geometry_size-1-i].first ); const NodeID current_edge_target_coordinate_id = forward_geometry[i].first; BOOST_ASSERT( current_edge_target_coordinate_id != current_edge_start_coordinate_id); + SimpleLogger().Write(logDEBUG) << " runs from coordinate " << current_edge_start_coordinate_id << " to " << current_edge_target_coordinate_id; + SimpleLogger().Write(logDEBUG) << " fwd edge: " << forward_geometry[i].second << ", rev edge: " << reverse_geometry[geometry_size-1-i].second; + SimpleLogger().Write(logDEBUG) << " fwd offset: " << forward_dist_prefix_sum[i] << ", rev offset: " << reverse_dist_prefix_sum[geometry_size-1-i]; // build edges m_edge_based_node_list.push_back( EdgeBasedNode( @@ -401,9 +419,9 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( current_edge_target_coordinate_id, forward_data.nameID, forward_geometry[i].second, - reverse_geometry[geometry_size-1-i].second, + reverse_geometry[i].second, forward_dist_prefix_sum[i], - reverse_dist_prefix_sum[geometry_size-1-i], + reverse_dist_prefix_sum[i], m_geometry_compressor.GetPositionForID(e1), i, belongs_to_tiny_cc @@ -640,6 +658,12 @@ void EdgeBasedGraphFactory::Run( if( !edge_data.forward ) { continue; } + const NodeID target = m_node_based_graph->GetTarget(current_edge); + + SimpleLogger().Write(logDEBUG) << "expanded node " << numbered_edges_count << " runs from " << + m_node_info_list.at(current_node).lat << "," << m_node_info_list.at(current_node).lon << " to " << + m_node_info_list.at(target).lat << "," << m_node_info_list.at(target).lon; + BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); edge_data.edgeBasedNodeID = numbered_edges_count; @@ -839,7 +863,7 @@ void EdgeBasedGraphFactory::Run( original_edge_data_vector.push_back( OriginalEdgeData( (edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v), - (edge_is_compressed ? edge_data1.nameID : edge_data1.nameID), + edge_data1.nameID, turn_instruction, edge_is_compressed ) @@ -857,6 +881,8 @@ void EdgeBasedGraphFactory::Run( BOOST_ASSERT( SPECIAL_NODEID != edge_data1.edgeBasedNodeID ); BOOST_ASSERT( SPECIAL_NODEID != edge_data2.edgeBasedNodeID ); + SimpleLogger().Write(logDEBUG) << "Generating expanded edge (" << edge_data1.edgeBasedNodeID << "," << edge_data2.edgeBasedNodeID << "), w: " << distance; + m_edge_based_edge_list.push_back( EdgeBasedEdge( edge_data1.edgeBasedNodeID, diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index c2b7c16d8..318b29d04 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include int current_free_list_maximum = 0; int UniqueNumber () { return ++current_free_list_maximum; } diff --git a/Contractor/GeometryCompressor.h b/Contractor/GeometryCompressor.h index 20f8a01aa..7d3593dc3 100644 --- a/Contractor/GeometryCompressor.h +++ b/Contractor/GeometryCompressor.h @@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #ifndef GEOMETRY_COMPRESSOR_H @@ -50,11 +49,6 @@ public: const EdgeWeight weight2 ); - // void AddLastViaNodeIDToCompressedEdge( - // const EdgeID edge_id, - // const NodeID node_id, - // const EdgeWeight weight - // ); bool HasEntryForID(const EdgeID edge_id) const; void PrintStatistics() const; void SerializeInternalVector(const std::string & path) const; diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index b0594b199..157affb1b 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -672,7 +672,7 @@ public: } double current_ratio = 0.; - double current_perpendicular_distance = current_edge.ComputePerpendicularDistance( + const double current_perpendicular_distance = current_edge.ComputePerpendicularDistance( m_coordinate_list->at(current_edge.u), m_coordinate_list->at(current_edge.v), input_coordinate, @@ -691,13 +691,13 @@ public: ) { //found a new minimum min_dist = current_perpendicular_distance; //TODO: use assignment c'tor in PhantomNode - result_phantom_node.forward_node_id = current_edge.reverse_edge_based_node_id; - result_phantom_node.reverse_node_id = current_edge.forward_edge_based_node_id; + result_phantom_node.forward_node_id = current_edge.forward_edge_based_node_id; + result_phantom_node.reverse_node_id = current_edge.reverse_edge_based_node_id; result_phantom_node.name_id = current_edge.name_id; - result_phantom_node.forward_weight = current_edge.reverse_weight; - result_phantom_node.reverse_weight = current_edge.forward_weight; - result_phantom_node.forward_offset = current_edge.reverse_offset; - result_phantom_node.reverse_offset = current_edge.forward_offset; + 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.packed_geometry_id = current_edge.packed_geometry_id; result_phantom_node.fwd_segment_position = current_edge.fwd_segment_position; @@ -758,10 +758,10 @@ public: ratio = std::min(1., ratio); } - SimpleLogger().Write(logDEBUG) << "result_phantom_node.forward_offset: " << result_phantom_node.forward_offset; - SimpleLogger().Write(logDEBUG) << "result_phantom_node.reverse_offset: " << result_phantom_node.reverse_offset; - SimpleLogger().Write(logDEBUG) << "result_phantom_node.forward_weight: " << result_phantom_node.forward_weight; - SimpleLogger().Write(logDEBUG) << "result_phantom_node.reverse_weight: " << result_phantom_node.reverse_weight; + SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.forward_offset: " << result_phantom_node.forward_offset; + SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.reverse_offset: " << result_phantom_node.reverse_offset; + SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.forward_weight: " << result_phantom_node.forward_weight; + SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.reverse_weight: " << result_phantom_node.reverse_weight; if (SPECIAL_NODEID != result_phantom_node.forward_node_id) { @@ -772,14 +772,14 @@ public: result_phantom_node.reverse_weight *= (1.-ratio); } - SimpleLogger().Write(logDEBUG) << "result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; - SimpleLogger().Write(logDEBUG) << "fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; - SimpleLogger().Write(logDEBUG) << "fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight; - SimpleLogger().Write(logDEBUG) << "fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset; - SimpleLogger().Write(logDEBUG) << "bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); - SimpleLogger().Write(logDEBUG) << "name id: " << result_phantom_node.name_id; - SimpleLogger().Write(logDEBUG) << "geom id: " << result_phantom_node.packed_geometry_id; - SimpleLogger().Write(logDEBUG) << "ratio: " << ratio; + SimpleLogger().Write(logDEBUG) << "[rtree] result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; + SimpleLogger().Write(logDEBUG) << "[rtree] fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; + SimpleLogger().Write(logDEBUG) << "[rtree] fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight; + SimpleLogger().Write(logDEBUG) << "[rtree] fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset; + SimpleLogger().Write(logDEBUG) << "[rtree] bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); + SimpleLogger().Write(logDEBUG) << "[rtree] name id: " << result_phantom_node.name_id; + SimpleLogger().Write(logDEBUG) << "[rtree] geom id: " << result_phantom_node.packed_geometry_id; + SimpleLogger().Write(logDEBUG) << "[rtree] ratio: " << ratio; return found_a_nearest_edge; } diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index 8eff2cbe3..d49ffb890 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -57,6 +57,8 @@ public: RawRouteData & raw_route_data ) const { + SimpleLogger().Write(logDEBUG) << "shrt path routing"; + BOOST_FOREACH( const PhantomNodes & phantom_node_pair, phantom_nodes_vector From 0f06c717961de138536c10683db60de8793549b4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Apr 2014 16:44:17 -0400 Subject: [PATCH 51/89] remove debug output --- Contractor/EdgeBasedGraphFactory.cpp | 77 ++++------------------------ 1 file changed, 9 insertions(+), 68 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 6b6e4f255..c516048cc 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -327,62 +327,29 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); BOOST_ASSERT( 0 != forward_geometry.size() ); - // int fwd_sum_of_weights = 0; - // NodeID fwd_start_node = u; - // BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, forward_geometry) { - // const NodeID fwd_end_node = geometry_node.first; - // const EdgeWeight fwd_weight = geometry_node.second; - // fwd_sum_of_weights += fwd_weight; - // fwd_start_node = fwd_end_node; - // } - - // BOOST_ASSERT( forward_data.distance == fwd_sum_of_weights ); - - // int rev_sum_of_weights = 0; - // NodeID rev_start_node = v; - // BOOST_FOREACH(const GeometryCompressor::CompressedNode & geometry_node, reverse_geometry) { - // const NodeID rev_end_node = geometry_node.first; - // const EdgeWeight rev_weight = geometry_node.second; - - // rev_sum_of_weights += rev_weight; - // rev_start_node = rev_end_node; - // } - - // BOOST_ASSERT( reverse_data.distance == rev_sum_of_weights ); - // reconstruct bidirectional edge with individual weights and put each into the NN index std::vector forward_dist_prefix_sum(forward_geometry.size(), 0); std::vector reverse_dist_prefix_sum(reverse_geometry.size(), 0); // quick'n'dirty prefix sum as std::partial_sum needs addtional casts - // SimpleLogger().Write(logDEBUG) << "Prefix sums of edge " << e1 << ", w: " << reverse_data.distance; + // TODO: move to lambda function with C++11 int temp_sum = 0; - std::cout << "\nfwd geom: "; for (unsigned i = 0; i < forward_geometry.size(); ++i) { forward_dist_prefix_sum[i] = temp_sum; temp_sum += forward_geometry[i].second; BOOST_ASSERT( forward_data.distance >= temp_sum ); - std::cout << forward_dist_prefix_sum[i] << " "; } - std::cout << std::endl; - // BOOST_ASSERT( forward_data.distance == temp_sum ); temp_sum = 0; - std::cout << "rev geom: "; for( unsigned i = 0; i < reverse_geometry.size(); ++i ) { temp_sum += reverse_geometry[reverse_geometry.size()-1-i].second; reverse_dist_prefix_sum[i] = reverse_data.distance - temp_sum; BOOST_ASSERT( reverse_data.distance >= temp_sum ); - - std::cout << reverse_dist_prefix_sum[i] << " "; } - std::cout << std::endl; - - // BOOST_ASSERT(false); BOOST_ASSERT( forward_geometry.size() == reverse_geometry.size() ); @@ -399,17 +366,12 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( max_id = std::max(reverse_data.edgeBasedNodeID, max_id); } - SimpleLogger().Write(logDEBUG) << "-> serializing packed edge " << forward_data.edgeBasedNodeID << "|" << reverse_data.edgeBasedNodeID; - // traverse arrays from start and end respectively for( unsigned i = 0; i < geometry_size; ++i ) { BOOST_ASSERT( current_edge_start_coordinate_id == reverse_geometry[geometry_size-1-i].first ); const NodeID current_edge_target_coordinate_id = forward_geometry[i].first; BOOST_ASSERT( current_edge_target_coordinate_id != current_edge_start_coordinate_id); - SimpleLogger().Write(logDEBUG) << " runs from coordinate " << current_edge_start_coordinate_id << " to " << current_edge_target_coordinate_id; - SimpleLogger().Write(logDEBUG) << " fwd edge: " << forward_geometry[i].second << ", rev edge: " << reverse_geometry[geometry_size-1-i].second; - SimpleLogger().Write(logDEBUG) << " fwd offset: " << forward_dist_prefix_sum[i] << ", rev offset: " << reverse_dist_prefix_sum[geometry_size-1-i]; // build edges m_edge_based_node_list.push_back( EdgeBasedNode( @@ -615,7 +577,6 @@ void EdgeBasedGraphFactory::Run( forward_weight1 + (add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty :0), forward_weight2 ); - SimpleLogger().Write(logDEBUG) << "compressing fwd segment with name " << m_node_based_graph->GetEdgeData(forward_e1).nameID; m_geometry_compressor.CompressEdge( reverse_e1, reverse_e2, @@ -624,7 +585,6 @@ void EdgeBasedGraphFactory::Run( reverse_weight1 , reverse_weight2 + (add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty :0) ); - SimpleLogger().Write(logDEBUG) << "compressing rev segment with name " << m_node_based_graph->GetEdgeData(reverse_e1).nameID; ++removed_node_count; BOOST_ASSERT @@ -646,7 +606,6 @@ void EdgeBasedGraphFactory::Run( } } SimpleLogger().Write() << "new nodes: " << new_node_count << ", edges " << new_edge_count; - SimpleLogger().Write(logDEBUG) << "Graph reports: " << m_node_based_graph->GetNumberOfEdges() << " edges"; SimpleLogger().Write() << "Node compression ratio: " << new_node_count/(double)original_number_of_nodes; SimpleLogger().Write() << "Edge compression ratio: " << new_edge_count/(double)original_number_of_edges; @@ -660,11 +619,6 @@ void EdgeBasedGraphFactory::Run( } const NodeID target = m_node_based_graph->GetTarget(current_edge); - SimpleLogger().Write(logDEBUG) << "expanded node " << numbered_edges_count << " runs from " << - m_node_info_list.at(current_node).lat << "," << m_node_info_list.at(current_node).lon << " to " << - m_node_info_list.at(target).lat << "," << m_node_info_list.at(target).lon; - - BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); edge_data.edgeBasedNodeID = numbered_edges_count; ++numbered_edges_count; @@ -673,7 +627,6 @@ void EdgeBasedGraphFactory::Run( } } - SimpleLogger().Write(logDEBUG) << "numbered " << numbered_edges_count << " edge-expanded nodes"; SimpleLogger().Write() << "Identifying components of the road network"; unsigned node_based_edge_counter = 0; @@ -881,8 +834,6 @@ void EdgeBasedGraphFactory::Run( BOOST_ASSERT( SPECIAL_NODEID != edge_data1.edgeBasedNodeID ); BOOST_ASSERT( SPECIAL_NODEID != edge_data2.edgeBasedNodeID ); - SimpleLogger().Write(logDEBUG) << "Generating expanded edge (" << edge_data1.edgeBasedNodeID << "," << edge_data2.edgeBasedNodeID << "), w: " << distance; - m_edge_based_edge_list.push_back( EdgeBasedEdge( edge_data1.edgeBasedNodeID, @@ -899,8 +850,6 @@ void EdgeBasedGraphFactory::Run( } FlushVectorToStream( edge_data_file, original_edge_data_vector ); - SimpleLogger().Write(logDEBUG) << "compressed: " << compressed; - edge_data_file.seekp( std::ios::beg ); edge_data_file.write( (char*)&original_edges_counter, sizeof(unsigned) ); edge_data_file.close(); @@ -908,22 +857,14 @@ void EdgeBasedGraphFactory::Run( SimpleLogger().Write(logDEBUG) << "serializing geometry to " << geometry_filename; m_geometry_compressor.SerializeInternalVector( geometry_filename ); - SimpleLogger().Write() << - "Generated " << m_edge_based_node_list.size() << " edge based nodes"; - SimpleLogger().Write() << - "Node-based graph contains " << node_based_edge_counter << " edges"; - SimpleLogger().Write() << - "Edge-expanded graph ..."; - SimpleLogger().Write() << - " contains " << m_edge_based_edge_list.size() << " edges"; - SimpleLogger().Write() << - " skips " << restricted_turns_counter << " turns, " - "defined by " << m_turn_restrictions_count << " restrictions"; - SimpleLogger().Write() << - " skips " << skipped_uturns_counter << " U turns"; - SimpleLogger().Write() << - " skips " << skipped_barrier_turns_counter << " turns over barriers"; - SimpleLogger().Write(logDEBUG) << "maximum written id: " << max_id; + SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " edge based nodes"; + SimpleLogger().Write() << "Node-based graph contains " << node_based_edge_counter << " edges"; + SimpleLogger().Write() << "Edge-expanded graph ..."; + SimpleLogger().Write() << " contains " << m_edge_based_edge_list.size() << " edges"; + SimpleLogger().Write() << " skips " << restricted_turns_counter << " turns, " + "defined by " << m_turn_restrictions_count << " restrictions"; + SimpleLogger().Write() << " skips " << skipped_uturns_counter << " U turns"; + SimpleLogger().Write() << " skips " << skipped_barrier_turns_counter << " turns over barriers"; } int EdgeBasedGraphFactory::GetTurnPenalty( From 4bb5270f250e7960628b4a624be7c0ebf2fdee23 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Apr 2014 17:47:39 -0400 Subject: [PATCH 52/89] cut back debug verbosity --- Contractor/EdgeBasedGraphFactory.cpp | 1 - Contractor/GeometryCompressor.cpp | 25 ++++++++++------------ DataStructures/StaticRTree.h | 24 ++++++++++----------- RoutingAlgorithms/AlternativePathRouting.h | 10 ++++----- RoutingAlgorithms/ShortestPathRouting.h | 12 ++++------- 5 files changed, 31 insertions(+), 41 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index c516048cc..f4575a656 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -617,7 +617,6 @@ void EdgeBasedGraphFactory::Run( if( !edge_data.forward ) { continue; } - const NodeID target = m_node_based_graph->GetTarget(current_edge); BOOST_ASSERT( numbered_edges_count < m_node_based_graph->GetNumberOfEdges() ); edge_data.edgeBasedNodeID = numbered_edges_count; diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 318b29d04..587984eb4 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -214,27 +214,24 @@ void GeometryCompressor::CompressEdge( void GeometryCompressor::PrintStatistics() const { - unsigned number_of_compressed_geometries = 0; - const unsigned compressed_edges = m_compressed_geometries.size(); - + const uint64_t compressed_edges = m_compressed_geometries.size(); + BOOST_ASSERT(0 == compressed_edges % 2); BOOST_ASSERT( m_compressed_geometries.size() + m_free_list.size() > 0 ); - unsigned long longest_chain_length = 0; + uint64_t number_of_compressed_geometries = 0; + uint64_t longest_chain_length = 0; BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) { number_of_compressed_geometries += current_vector.size(); - longest_chain_length = std::max(longest_chain_length, current_vector.size()); + longest_chain_length = std::max(longest_chain_length, (uint64_t)current_vector.size()); } - BOOST_ASSERT(0 == compressed_edges % 2); - SimpleLogger().Write() << - "compressed edges: " << compressed_edges << - ", compressed geometries: " << number_of_compressed_geometries << - ", longest chain length: " << longest_chain_length << - ", cmpr ratio: " << ((float)compressed_edges/std::max(number_of_compressed_geometries, 1u) ) << - ", avg chain length: " << (float)number_of_compressed_geometries/std::max(1u, compressed_edges); - SimpleLogger().Write() << - "No bytes: " << 4*compressed_edges + number_of_compressed_geometries*4 +8; + SimpleLogger().Write() << "Geometry successfully removed:" + "\n compressed edges: " << compressed_edges << + "\n compressed geometries: " << number_of_compressed_geometries << + "\n longest chain length: " << longest_chain_length << + "\n cmpr ratio: " << ((float)compressed_edges/std::max(number_of_compressed_geometries, (uint64_t)1) ) << + "\n avg chain length: " << (float)number_of_compressed_geometries/std::max((uint64_t)1, compressed_edges); } const std::vector & GeometryCompressor::GetBucketReference( diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 157affb1b..a2b936c84 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -758,10 +758,10 @@ public: ratio = std::min(1., ratio); } - SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.forward_offset: " << result_phantom_node.forward_offset; - SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.reverse_offset: " << result_phantom_node.reverse_offset; - SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.forward_weight: " << result_phantom_node.forward_weight; - SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.reverse_weight: " << result_phantom_node.reverse_weight; + // SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.forward_offset: " << result_phantom_node.forward_offset; + // SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.reverse_offset: " << result_phantom_node.reverse_offset; + // SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.forward_weight: " << result_phantom_node.forward_weight; + // SimpleLogger().Write(logDEBUG) << "[rtree] result_phantom_node.reverse_weight: " << result_phantom_node.reverse_weight; if (SPECIAL_NODEID != result_phantom_node.forward_node_id) { @@ -772,14 +772,14 @@ public: result_phantom_node.reverse_weight *= (1.-ratio); } - SimpleLogger().Write(logDEBUG) << "[rtree] result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; - SimpleLogger().Write(logDEBUG) << "[rtree] fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; - SimpleLogger().Write(logDEBUG) << "[rtree] fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight; - SimpleLogger().Write(logDEBUG) << "[rtree] fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset; - SimpleLogger().Write(logDEBUG) << "[rtree] bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); - SimpleLogger().Write(logDEBUG) << "[rtree] name id: " << result_phantom_node.name_id; - SimpleLogger().Write(logDEBUG) << "[rtree] geom id: " << result_phantom_node.packed_geometry_id; - SimpleLogger().Write(logDEBUG) << "[rtree] ratio: " << ratio; + // SimpleLogger().Write(logDEBUG) << "[rtree] result location: " << result_phantom_node.location << ", start: " << current_start_coordinate << ", end: " << current_end_coordinate; + // SimpleLogger().Write(logDEBUG) << "[rtree] fwd node: " << result_phantom_node.forward_node_id << ", rev node: " << result_phantom_node.reverse_node_id; + // SimpleLogger().Write(logDEBUG) << "[rtree] fwd weight: " << result_phantom_node.forward_weight << ", rev weight: " << result_phantom_node.reverse_weight; + // SimpleLogger().Write(logDEBUG) << "[rtree] fwd offset: " << result_phantom_node.forward_offset << ", rev offset: " << result_phantom_node.reverse_offset; + // SimpleLogger().Write(logDEBUG) << "[rtree] bidirected: " << (result_phantom_node.isBidirected() ? "y" : "n"); + // SimpleLogger().Write(logDEBUG) << "[rtree] name id: " << result_phantom_node.name_id; + // SimpleLogger().Write(logDEBUG) << "[rtree] geom id: " << result_phantom_node.packed_geometry_id; + // SimpleLogger().Write(logDEBUG) << "[rtree] ratio: " << ratio; return found_a_nearest_edge; } diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index b0ac3237f..5315b04ca 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -83,13 +83,11 @@ public: const PhantomNodes & phantom_node_pair, RawRouteData & raw_route_data ) { - SimpleLogger().Write(logDEBUG) << "alt path routing"; if( //phantom_node_pair.AtLeastOnePhantomNodeIsInvalid() || phantom_node_pair.PhantomNodesHaveEqualLocation() ) { // raw_route_data.lengthOfShortestPath = INVALID_EDGE_WEIGHT; // raw_route_data.lengthOfAlternativePath = INVALID_EDGE_WEIGHT; - // SimpleLogger().Write(logDEBUG) << "not executing path search"; return; } @@ -117,7 +115,7 @@ public: int upper_bound_to_shortest_path_distance = INVALID_EDGE_WEIGHT; NodeID middle_node = SPECIAL_NODEID; if(phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd-a insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "fwd-a insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.source_phantom.forward_node_id, -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), @@ -125,7 +123,7 @@ public: ); } if(phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd-b insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "fwd-b insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.source_phantom.reverse_node_id, -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), @@ -134,7 +132,7 @@ public: } if(phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev-a insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "rev-a insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.target_phantom.forward_node_id, phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(), @@ -142,7 +140,7 @@ public: ); } if(phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev-b insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "rev-b insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.target_phantom.reverse_node_id, phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(), diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index d49ffb890..aef1eabfd 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -57,8 +57,6 @@ public: RawRouteData & raw_route_data ) const { - SimpleLogger().Write(logDEBUG) << "shrt path routing"; - BOOST_FOREACH( const PhantomNodes & phantom_node_pair, phantom_nodes_vector @@ -66,8 +64,6 @@ public: if( phantom_node_pair.AtLeastOnePhantomNodeIsInvalid() ) { // raw_route_data.lengthOfShortestPath = INT_MAX; // raw_route_data.lengthOfAlternativePath = INT_MAX; - SimpleLogger().Write(logDEBUG) << "returning early"; - return; } } @@ -113,7 +109,7 @@ public: search_from_1st_node && phantom_node_pair.source_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.forward_node_id << ", w: " << -phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.source_phantom.forward_node_id, distance1-phantom_node_pair.source_phantom.GetForwardWeightPlusOffset(), @@ -129,7 +125,7 @@ public: search_from_2nd_node && phantom_node_pair.source_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "fwd1 insert: " << phantom_node_pair.source_phantom.reverse_node_id << ", w: " << -phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(); forward_heap1.Insert( phantom_node_pair.source_phantom.reverse_node_id, distance2-phantom_node_pair.source_phantom.GetReverseWeightPlusOffset(), @@ -144,7 +140,7 @@ public: //insert new backward nodes into backward heap, unadjusted. if( phantom_node_pair.target_phantom.forward_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.forward_node_id << ", w: " << phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(); reverse_heap1.Insert( phantom_node_pair.target_phantom.forward_node_id, phantom_node_pair.target_phantom.GetForwardWeightPlusOffset(), @@ -153,7 +149,7 @@ public: } if( phantom_node_pair.target_phantom.reverse_node_id != SPECIAL_NODEID ) { - SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); + // SimpleLogger().Write(logDEBUG) << "rev insert: " << phantom_node_pair.target_phantom.reverse_node_id << ", w: " << phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(); reverse_heap2.Insert( phantom_node_pair.target_phantom.reverse_node_id, phantom_node_pair.target_phantom.GetReverseWeightPlusOffset(), From 6d8465a04d2dd7731ddd5fe24cdd16c4ec89b9ff Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Apr 2014 19:08:13 -0400 Subject: [PATCH 53/89] implement geometry uncompressing using STL --- Server/DataStructures/InternalDataFacade.h | 48 +++++++++------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index d04d1dba9..0e6769864 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -71,8 +71,8 @@ private: ShM::vector m_names_char_list; ShM::vector m_name_begin_indices; ShM::vector m_egde_is_compressed; - ShM::vector m_compressed_geometry_indices; - ShM::vector m_compressed_geometries; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; boost::shared_ptr< StaticRTree< @@ -189,9 +189,8 @@ private: edges_input_stream.close(); } - void LoadGeometries( - const boost::filesystem::path & geometry_file - ) { + void LoadGeometries(const boost::filesystem::path & geometry_file) + { std::ifstream geometry_stream( geometry_file.c_str(), std::ios::binary @@ -203,9 +202,9 @@ private: (char *)&number_of_indices, sizeof(unsigned) ); - m_compressed_geometry_indices.resize(number_of_indices); + m_geometry_indices.resize(number_of_indices); geometry_stream.read( - (char *)&(m_compressed_geometry_indices[0]), + (char *)&(m_geometry_indices[0]), number_of_indices*sizeof(unsigned) ); @@ -214,17 +213,14 @@ private: sizeof(unsigned) ); - BOOST_ASSERT( m_compressed_geometry_indices.back() == number_of_compressed_geometries ); - m_compressed_geometries.resize( number_of_compressed_geometries ); + BOOST_ASSERT( m_geometry_indices.back() == number_of_compressed_geometries ); + m_geometry_list.resize( number_of_compressed_geometries ); geometry_stream.read( - (char *)&(m_compressed_geometries[0]), + (char *)&(m_geometry_list[0]), number_of_compressed_geometries*sizeof(unsigned) ); geometry_stream.close(); - - SimpleLogger().Write() << "number_of_indices: " << number_of_indices; - SimpleLogger().Write() << "number_of_compressed_geometries: " << number_of_compressed_geometries; } void LoadRTree( @@ -290,6 +286,9 @@ public: if( server_paths.find("fileindex") == server_paths.end() ) { throw OSRMException("no leaf index file given in ini file"); } + if( server_paths.find("geometries") == server_paths.end() ) { + throw OSRMException("no geometries file given in ini file"); + } if( server_paths.find("nodesdata") == server_paths.end() ) { throw OSRMException("no nodes file given in ini file"); } @@ -478,23 +477,16 @@ public: } virtual void GetUncompressedGeometry( - const unsigned node, std::vector & result_nodes + const unsigned id, std::vector & result_nodes ) const { - // const NodeID node = m_via_node_list.at(id); - // SimpleLogger().Write() << "translated " << id << " to " << node; - // SimpleLogger().Write() << "getting geometry from compression bucket " << node << "/" << m_compressed_geometry_indices.size(); - unsigned begin = m_compressed_geometry_indices.at(node); - unsigned end = m_compressed_geometry_indices.at(node+1); - // SimpleLogger().Write() << "bucket " << node << " has range [" << begin << "," << end-1 << "]"; - //TODO: use vector.insert(.) - for(unsigned geometry_index = begin; geometry_index < end; ++geometry_index) { - 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); - } - } + const unsigned begin = m_geometry_indices.at(id); + const unsigned end = m_geometry_indices.at(id+1); + result_nodes.clear(); + result_nodes.insert(result_nodes.begin(), + m_geometry_list.begin() + begin, + m_geometry_list.begin() + end); + } std::string GetTimestamp() const { return m_timestamp; From f2be495e9572e541d5555e6319c330bc16647621 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 10 Apr 2014 19:10:00 -0400 Subject: [PATCH 54/89] implement shared data facade geometry loader and getter functions --- Server/DataStructures/SharedDataFacade.h | 40 +++++++++++++++++++--- Server/DataStructures/SharedDataType.h | 42 +++++++++++++++++++++++- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 33ce972bc..429f44b27 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -80,6 +80,10 @@ private: ShM::vector m_turn_instruction_list; ShM::vector m_names_char_list; ShM::vector m_name_begin_indices; + ShM::vector m_egde_is_compressed; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; + boost::shared_ptr< StaticRTree< RTreeLeaf, @@ -203,6 +207,28 @@ private: m_names_char_list.swap(names_char_list); } + void LoadGeometries() + { + unsigned * geometries_index_ptr = (unsigned *)( + shared_memory + data_layout->GetGeometriesIndicesOffset() + ); + + typename ShM::vector geometry_begin_indices( + geometries_index_ptr, + data_layout->geometries_index_list_size + ); + m_geometry_indices.swap(geometry_begin_indices); + + unsigned * geometries_list_ptr = (unsigned *)( + shared_memory + data_layout->GetGeometryListOffset() + ); + typename ShM::vector geometry_list( + geometries_list_ptr, + data_layout->geometries_list_size + ); + m_geometry_list.swap(geometry_list); + } + public: SharedDataFacade( ) { data_timestamp_ptr = (SharedDataTimestamp *)SharedMemoryFactory::Get( @@ -254,7 +280,7 @@ public: LoadGraph(); LoadNodeAndEdgeInformation(); - //TODO: LoadGeometries(); + LoadGeometries(); LoadRTree(ram_index_path); LoadTimestamp(); LoadViaNodeList(); @@ -321,19 +347,23 @@ public: FixedPointCoordinate GetCoordinateOfNode( const unsigned id ) const { - // const NodeID node = m_via_node_list.at(id); return m_coordinate_list->at(id); }; virtual bool EdgeIsCompressed( const unsigned id ) const { - //TODO!! - return false; + return m_egde_is_compressed.at(id); } virtual void GetUncompressedGeometry( const unsigned id, std::vector & result_nodes ) const { - //TODO!! + const unsigned begin = m_geometry_indices.at(id); + const unsigned end = m_geometry_indices.at(id+1); + + result_nodes.clear(); + result_nodes.insert(result_nodes.begin(), + m_geometry_list.begin() + begin, + m_geometry_list.begin() + end); } virtual unsigned GetGeometryIndexForEdgeID(const unsigned id) const { diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 49cfac0a4..0da5ff504 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -56,6 +56,8 @@ struct SharedDataLayout { uint64_t coordinate_list_size; uint64_t turn_instruction_list_size; uint64_t r_search_tree_size; + uint64_t geometries_index_list_size; + uint64_t geometries_list_size; unsigned checksum; unsigned timestamp_length; @@ -72,8 +74,11 @@ struct SharedDataLayout { coordinate_list_size(0), turn_instruction_list_size(0), r_search_tree_size(0), + geometries_index_list_size(0), + geometries_list_size(0), checksum(0), timestamp_length(0) + { ram_index_file_name[0] = '\0'; } @@ -90,6 +95,8 @@ struct SharedDataLayout { 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) << "geometries_index_list_size: " << geometries_index_list_size; + SimpleLogger().Write(logDEBUG) << "geometry_list_size: " << geometries_list_size; SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); SimpleLogger().Write(logDEBUG) << "ram index file name: " << ram_index_file_name; } @@ -106,6 +113,8 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_index_list_size * sizeof(unsigned) ) + + (geometries_list_size * sizeof(unsigned) ) + sizeof(checksum) + 1024*sizeof(char); return result; @@ -195,7 +204,7 @@ struct SharedDataLayout { (turn_instruction_list_size * sizeof(TurnInstructionsClass)); return result; } - uint64_t GetChecksumOffset() const { + uint64_t GetGeometriesIndicesOffset() const { uint64_t result = (name_index_list_size * sizeof(unsigned) ) + (name_char_list_size * sizeof(char) ) + @@ -209,6 +218,37 @@ struct SharedDataLayout { (r_search_tree_size * sizeof(RTreeNode) ); return result; } + uint64_t GetGeometryListOffset() const { + uint64_t result = + (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) ) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_index_list_size * sizeof(unsigned) ); + return result; + } + uint64_t GetChecksumOffset() const { + uint64_t result = + (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) ) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_index_list_size * sizeof(unsigned) ) + + (geometries_list_size * sizeof(unsigned) ); + return result; + } }; enum SharedDataType { From db5fd5506dea9aba660578baabb56ed7e548354c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 14:03:09 -0400 Subject: [PATCH 55/89] partial implementation of new datastore functions --- DataStructures/SharedMemoryVectorWrapper.h | 58 ++++++++++++++++++++++ Server/DataStructures/SharedDataFacade.h | 16 ++++-- Server/DataStructures/SharedDataType.h | 23 +++++++++ 3 files changed, 93 insertions(+), 4 deletions(-) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 22337188e..536a7c5e2 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -128,6 +128,64 @@ public: } }; +template<> +class SharedMemoryWrapper { +private: + unsigned * m_ptr; + std::size_t m_size; + +public: + SharedMemoryWrapper() : + m_ptr(NULL), + m_size(0) + { } + + SharedMemoryWrapper(unsigned * ptr, std::size_t size) : + m_ptr(ptr), + m_size(size) + { } + + 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 ); + } + + // 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; + // } + + bool at(const std::size_t index) const { + BOOST_ASSERT_MSG(index < m_size, "invalid size"); + const unsigned bucket = index / 32; + const unsigned offset = index % 32; + return m_ptr[bucket] & (1 << offset); + } + + // ShMemIterator begin() const { + // return ShMemIterator(m_ptr); + // } + + // ShMemIterator end() const { + // return ShMemIterator(m_ptr+m_size); + // } + + std::size_t size() const { return m_size; } + + bool empty() const { return 0 == size(); } + + bool operator[](const unsigned index) { + BOOST_ASSERT_MSG(index < m_size, "invalid size"); + const unsigned bucket = index / 32; + const unsigned offset = index % 32; + return m_ptr[bucket] & (1 << offset); + } +}; + + template struct ShM { typedef typename boost::conditional< diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 429f44b27..31ec27a66 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -80,9 +80,9 @@ private: ShM::vector m_turn_instruction_list; ShM::vector m_names_char_list; ShM::vector m_name_begin_indices; - ShM::vector m_egde_is_compressed; - ShM::vector m_geometry_indices; - ShM::vector m_geometry_list; + ShM::vector m_egde_is_compressed; + ShM::vector m_geometry_indices; + ShM::vector m_geometry_list; boost::shared_ptr< StaticRTree< @@ -209,10 +209,18 @@ private: void LoadGeometries() { + unsigned * geometries_compressed_ptr = (unsigned *)( + shared_memory + data_layout->GetGeometriesCompressedOffset() + ); + typename ShM::vector egde_is_compressed( + geometries_compressed_ptr, + data_layout->geometries_index_list_size + ); + m_egde_is_compressed.swap(egde_is_compressed); + unsigned * geometries_index_ptr = (unsigned *)( shared_memory + data_layout->GetGeometriesIndicesOffset() ); - typename ShM::vector geometry_begin_indices( geometries_index_ptr, data_layout->geometries_index_list_size diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 0da5ff504..a2bcdbc0c 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -58,6 +58,7 @@ struct SharedDataLayout { uint64_t r_search_tree_size; uint64_t geometries_index_list_size; uint64_t geometries_list_size; + uint64_t geometries_compression; unsigned checksum; unsigned timestamp_length; @@ -76,6 +77,7 @@ struct SharedDataLayout { r_search_tree_size(0), geometries_index_list_size(0), geometries_list_size(0), + geometries_compression(0), checksum(0), timestamp_length(0) @@ -95,6 +97,7 @@ struct SharedDataLayout { 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) << "geometries_compression: " << geometries_compression; SimpleLogger().Write(logDEBUG) << "geometries_index_list_size: " << geometries_index_list_size; SimpleLogger().Write(logDEBUG) << "geometry_list_size: " << geometries_list_size; SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); @@ -218,6 +221,24 @@ struct SharedDataLayout { (r_search_tree_size * sizeof(RTreeNode) ); return result; } + + uint64_t GetGeometriesCompressedOffset() const + { + uint64_t result = + (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) ) + + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + + (timestamp_length * sizeof(char) ) + + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_compression/32) + 1; + return result; + } + uint64_t GetGeometryListOffset() const { uint64_t result = (name_index_list_size * sizeof(unsigned) ) + @@ -230,6 +251,7 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_compression/32) + 1 + (geometries_index_list_size * sizeof(unsigned) ); return result; } @@ -245,6 +267,7 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_compression/32) + 1 + (geometries_index_list_size * sizeof(unsigned) ) + (geometries_list_size * sizeof(unsigned) ); return result; From 038e8cc8b85ca8853203cfa65e11bd642a5f3564 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 14:03:39 -0400 Subject: [PATCH 56/89] remove unneeded edge-offset during query --- RoutingAlgorithms/AlternativePathRouting.h | 25 +++++++--------------- RoutingAlgorithms/BasicRoutingInterface.h | 3 +-- RoutingAlgorithms/ShortestPathRouting.h | 4 ---- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index 5315b04ca..adc97126e 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -168,8 +168,7 @@ public: &middle_node, &upper_bound_to_shortest_path_distance, via_node_candidate_list, - forward_search_space, - 0 + forward_search_space ); } if(0 < reverse_heap1.Size()){ @@ -179,8 +178,7 @@ public: &middle_node, &upper_bound_to_shortest_path_distance, via_node_candidate_list, - reverse_search_space, - 0 + reverse_search_space ); } } @@ -284,7 +282,7 @@ public: //prioritizing via nodes for deep inspection BOOST_FOREACH(const NodeID node, preselected_node_list) { int length_of_via_path = 0, sharing_of_via_path = 0; - ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path, 0, packed_shortest_path); + ComputeLengthAndSharingOfViaPath(node, &length_of_via_path, &sharing_of_via_path, packed_shortest_path); const int maximum_allowed_sharing = upper_bound_to_shortest_path_distance*VIAPATH_GAMMA; if( sharing_of_via_path <= maximum_allowed_sharing && length_of_via_path <= upper_bound_to_shortest_path_distance*(1+VIAPATH_EPSILON)) { ranked_candidates_list.push_back( @@ -305,7 +303,7 @@ public: int length_of_via_path = INVALID_EDGE_WEIGHT; NodeID s_v_middle = SPECIAL_NODEID, v_t_middle = SPECIAL_NODEID; BOOST_FOREACH(const RankedCandidateNode & candidate, ranked_candidates_list){ - if(ViaNodeCandidatePassesTTest(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate, 0, upper_bound_to_shortest_path_distance, &length_of_via_path, &s_v_middle, &v_t_middle)) { + if(ViaNodeCandidatePassesTTest(forward_heap1, reverse_heap1, forward_heap2, reverse_heap2, candidate, upper_bound_to_shortest_path_distance, &length_of_via_path, &s_v_middle, &v_t_middle)) { // select first admissable selected_via_node = candidate.node; break; @@ -417,7 +415,6 @@ private: const NodeID via_node, int *real_length_of_via_path, int *sharing_of_via_path, - const int offset, const std::vector & packed_shortest_path ) { engine_working_data.InitializeOrClearSecondThreadLocalStorage( @@ -445,7 +442,6 @@ private: existing_forward_heap, &s_v_middle, &upper_bound_s_v_path_length, - 2 * offset, false ); } @@ -459,7 +455,6 @@ private: existing_reverse_heap, &v_t_middle, &upper_bound_of_v_t_path_length, - 2 * offset, true ); } @@ -627,8 +622,7 @@ private: NodeID * middle_node, int * upper_bound_to_shortest_path_distance, std::vector & search_space_intersection, - std::vector & search_space, - const int edge_expansion_offset + std::vector & search_space ) const { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); @@ -653,7 +647,7 @@ private: const int new_distance = reverse_heap.GetKey(node) + distance; if (new_distance < *upper_bound_to_shortest_path_distance) { - if ((new_distance + edge_expansion_offset) >= 0) + if (new_distance >= 0) { *middle_node = node; *upper_bound_to_shortest_path_distance = new_distance; @@ -699,7 +693,6 @@ private: QueryHeap& new_forward_heap, QueryHeap& new_reverse_heap, const RankedCandidateNode& candidate, - const int offset, const int lengthOfShortestPath, int * length_of_via_path, NodeID * s_v_middle, @@ -715,7 +708,7 @@ private: //compute path by reusing forward search from s new_reverse_heap.Insert(candidate.node, 0, candidate.node); while (new_reverse_heap.Size() > 0) { - super::RoutingStep(new_reverse_heap, existing_forward_heap, s_v_middle, &upper_bound_s_v_path_length, 2*offset, false); + super::RoutingStep(new_reverse_heap, existing_forward_heap, s_v_middle, &upper_bound_s_v_path_length, false); } if( INVALID_EDGE_WEIGHT == upper_bound_s_v_path_length ) { @@ -727,7 +720,7 @@ private: int upper_bound_of_v_t_path_length = INVALID_EDGE_WEIGHT; new_forward_heap.Insert(candidate.node, 0, candidate.node); while (new_forward_heap.Size() > 0) { - super::RoutingStep(new_forward_heap, existing_reverse_heap, v_t_middle, &upper_bound_of_v_t_path_length, 2*offset, true); + super::RoutingStep(new_forward_heap, existing_reverse_heap, v_t_middle, &upper_bound_of_v_t_path_length, true); } if( INVALID_EDGE_WEIGHT == upper_bound_of_v_t_path_length ){ @@ -891,7 +884,6 @@ private: reverse_heap3, &middle, &upper_bound, - offset, true ); } @@ -901,7 +893,6 @@ private: forward_heap3, &middle, &upper_bound, - offset, false ); } diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 4071734c7..5efe5279e 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -62,7 +62,6 @@ public: SearchEngineData::QueryHeap & reverse_heap, NodeID * middle_node_id, int * upper_bound, - const int edge_expansion_offset, const bool forward_direction ) const { @@ -75,7 +74,7 @@ public: // SimpleLogger().Write(logDEBUG) << "new_distance: " << new_distance; if(new_distance < *upper_bound ) { - if( new_distance + edge_expansion_offset >= 0 ) + if (new_distance >= 0) { *middle_node_id = node; *upper_bound = new_distance; diff --git a/RoutingAlgorithms/ShortestPathRouting.h b/RoutingAlgorithms/ShortestPathRouting.h index aef1eabfd..45dffc411 100644 --- a/RoutingAlgorithms/ShortestPathRouting.h +++ b/RoutingAlgorithms/ShortestPathRouting.h @@ -174,7 +174,6 @@ public: reverse_heap1, &middle1, &local_upper_bound1, - 0, true ); } @@ -184,7 +183,6 @@ public: forward_heap1, &middle1, &local_upper_bound1, - 0, false ); } @@ -198,7 +196,6 @@ public: reverse_heap2, &middle2, &local_upper_bound2, - 0, true ); } @@ -208,7 +205,6 @@ public: forward_heap2, &middle2, &local_upper_bound2, - 0, false ); } From 39914cd9331bbb72c103392fe465dc3e2c39f0e6 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 15:40:44 -0400 Subject: [PATCH 57/89] remove some debug code --- Descriptors/JSONDescriptor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 559e8e2db..390422c78 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -129,13 +129,13 @@ public: return; } - std::string name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); + // std::string name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); int fwd_weight = phantom_nodes.source_phantom.forward_weight; int rev_weight = phantom_nodes.source_phantom.reverse_weight; int fwd_offset = phantom_nodes.source_phantom.forward_offset; int rev_offset = phantom_nodes.source_phantom.reverse_offset; // SimpleLogger().Write(logDEBUG) << "json source: " << name << ", location: " << phantom_nodes.source_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); + // name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); fwd_weight = phantom_nodes.target_phantom.forward_weight; rev_weight = phantom_nodes.target_phantom.reverse_weight; fwd_offset = phantom_nodes.target_phantom.forward_offset; From 4f85fd28cf3a246de65e7deadb89514547573576 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 16:24:48 -0400 Subject: [PATCH 58/89] add todo for the switch to C++11 --- Contractor/Contractor.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 357f05b6d..64e2eac37 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -737,6 +737,7 @@ private: if ( std::abs(priority - targetPriority) < std::numeric_limits::epsilon() && bias(node, target) ) { return false; } + // TODO: C++11 copy_if with lambda neighbours.push_back( target ); } From a4d6e5c9ccf0dd7284c255e1b2b47b75eef3758e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 16:25:25 -0400 Subject: [PATCH 59/89] reformat geometry compressor according to new guidelines --- Contractor/GeometryCompressor.cpp | 149 +++++++++++++----------------- Contractor/GeometryCompressor.h | 29 +++--- 2 files changed, 80 insertions(+), 98 deletions(-) diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 587984eb4..2115d9b77 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -29,13 +29,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../Util/SimpleLogger.h" #include +#include +#include #include -#include #include int current_free_list_maximum = 0; -int UniqueNumber () { return ++current_free_list_maximum; } +int UniqueNumber() { return ++current_free_list_maximum; } GeometryCompressor::GeometryCompressor() { @@ -46,7 +47,7 @@ GeometryCompressor::GeometryCompressor() void GeometryCompressor::IncreaseFreeList() { m_compressed_geometries.resize(m_compressed_geometries.size() + 100); - for(unsigned i = 100; i > 0; --i) + for (unsigned i = 100; i > 0; --i) { m_free_list.push_back(current_free_list_maximum); ++current_free_list_maximum; @@ -62,88 +63,68 @@ unsigned GeometryCompressor::GetPositionForID(const EdgeID edge_id) const { boost::unordered_map::const_iterator map_iterator; map_iterator = m_edge_id_to_list_index_map.find(edge_id); - BOOST_ASSERT( map_iterator != m_edge_id_to_list_index_map.end() ); - BOOST_ASSERT( map_iterator->second < m_compressed_geometries.size() ); + BOOST_ASSERT(map_iterator != m_edge_id_to_list_index_map.end()); + BOOST_ASSERT(map_iterator->second < m_compressed_geometries.size()); return map_iterator->second; } -void GeometryCompressor::SerializeInternalVector(const std::string & path) const +void GeometryCompressor::SerializeInternalVector(const std::string &path) const { - std::ofstream geometry_out_stream( path.c_str(), std::ios::binary ); - const unsigned number_of_compressed_geometries = m_compressed_geometries.size()+1; - BOOST_ASSERT( UINT_MAX != number_of_compressed_geometries ); - geometry_out_stream.write( - (char*)&number_of_compressed_geometries, - sizeof(unsigned) - ); - - SimpleLogger().Write(logDEBUG) << "number_of_compressed_geometries: " << number_of_compressed_geometries; + boost::filesystem::fstream geometry_out_stream(path, std::ios::binary|std::ios::out); + const unsigned number_of_compressed_geometries = m_compressed_geometries.size() + 1; + BOOST_ASSERT(UINT_MAX != number_of_compressed_geometries); + geometry_out_stream.write((char *)&number_of_compressed_geometries, sizeof(unsigned)); // write indices array unsigned prefix_sum_of_list_indices = 0; for (unsigned i = 0; i < m_compressed_geometries.size(); ++i) { - geometry_out_stream.write( - (char*)&prefix_sum_of_list_indices, - sizeof(unsigned) - ); + geometry_out_stream.write((char *)&prefix_sum_of_list_indices, sizeof(unsigned)); - const std::vector & current_vector = m_compressed_geometries.at(i); + const std::vector ¤t_vector = m_compressed_geometries.at(i); const unsigned unpacked_size = current_vector.size(); - BOOST_ASSERT( UINT_MAX != unpacked_size ); + BOOST_ASSERT(UINT_MAX != unpacked_size); prefix_sum_of_list_indices += unpacked_size; } // sentinel element - geometry_out_stream.write( - (char*)&prefix_sum_of_list_indices, - sizeof(unsigned) - ); + geometry_out_stream.write((char *)&prefix_sum_of_list_indices, sizeof(unsigned)); // number of geometry entries to follow, it is the (inclusive) prefix sum - geometry_out_stream.write( - (char*)&prefix_sum_of_list_indices, - sizeof(unsigned) - ); + geometry_out_stream.write((char *)&prefix_sum_of_list_indices, sizeof(unsigned)); - SimpleLogger().Write(logDEBUG) << "number of geometry nodes: " << prefix_sum_of_list_indices; unsigned control_sum = 0; // write compressed geometries for (unsigned i = 0; i < m_compressed_geometries.size(); ++i) { - const std::vector & current_vector = m_compressed_geometries[i]; + const std::vector ¤t_vector = m_compressed_geometries[i]; const unsigned unpacked_size = current_vector.size(); control_sum += unpacked_size; - BOOST_ASSERT( UINT_MAX != unpacked_size ); + BOOST_ASSERT(UINT_MAX != unpacked_size); BOOST_FOREACH (const CompressedNode current_node, current_vector) { - geometry_out_stream.write( - (char*)&(current_node.first), - sizeof(NodeID) - ); + geometry_out_stream.write((char *)&(current_node.first), sizeof(NodeID)); } } - BOOST_ASSERT( control_sum == prefix_sum_of_list_indices ); + BOOST_ASSERT(control_sum == prefix_sum_of_list_indices); // all done, let's close the resource geometry_out_stream.close(); } -void GeometryCompressor::CompressEdge( - const EdgeID edge_id_1, - const EdgeID edge_id_2, - const NodeID via_node_id, - const NodeID target_node_id, - const EdgeWeight weight1, - const EdgeWeight weight2 -) { - //TODO: remove super-trivial geometries - - BOOST_ASSERT( SPECIAL_EDGEID != edge_id_1 ); - BOOST_ASSERT( SPECIAL_EDGEID != edge_id_2 ); - BOOST_ASSERT( SPECIAL_NODEID != via_node_id ); - BOOST_ASSERT( SPECIAL_NODEID != target_node_id ); - BOOST_ASSERT( std::numeric_limits::max() != weight1 ); - BOOST_ASSERT( std::numeric_limits::max() != weight2 ); +void GeometryCompressor::CompressEdge(const EdgeID edge_id_1, + const EdgeID edge_id_2, + const NodeID via_node_id, + const NodeID target_node_id, + const EdgeWeight weight1, + const EdgeWeight weight2) +{ + // remove super-trivial geometries + BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1); + BOOST_ASSERT(SPECIAL_EDGEID != edge_id_2); + BOOST_ASSERT(SPECIAL_NODEID != via_node_id); + BOOST_ASSERT(SPECIAL_NODEID != target_node_id); + BOOST_ASSERT(std::numeric_limits::max() != weight1); + BOOST_ASSERT(std::numeric_limits::max() != weight2); // append list of removed edge_id plus via node to surviving edge id: // & edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1]; + std::vector &edge_bucket_list1 = m_compressed_geometries[edge_bucket_id1]; if (edge_bucket_list1.empty()) { - edge_bucket_list1.push_back( std::make_pair(via_node_id, weight1) ); + edge_bucket_list1.push_back(std::make_pair(via_node_id, weight1)); } - BOOST_ASSERT( 0 < edge_bucket_list1.size() ); - BOOST_ASSERT( !edge_bucket_list1.empty() ); + BOOST_ASSERT(0 < edge_bucket_list1.size()); + BOOST_ASSERT(!edge_bucket_list1.empty()); if (HasEntryForID(edge_id_2)) { // second edge is not atomic anymore const unsigned list_to_remove_index = GetPositionForID(edge_id_2); - BOOST_ASSERT( list_to_remove_index < m_compressed_geometries.size() ); + BOOST_ASSERT(list_to_remove_index < m_compressed_geometries.size()); - std::vector & edge_bucket_list2 = m_compressed_geometries[list_to_remove_index]; + std::vector &edge_bucket_list2 = + m_compressed_geometries[list_to_remove_index]; // found an existing list, append it to the list of edge_id_1 edge_bucket_list1.insert( - edge_bucket_list1.end(), - edge_bucket_list2.begin(), - edge_bucket_list2.end() - ); + edge_bucket_list1.end(), edge_bucket_list2.begin(), edge_bucket_list2.end()); - //remove the list of edge_id_2 + // remove the list of edge_id_2 m_edge_id_to_list_index_map.erase(edge_id_2); - BOOST_ASSERT( m_edge_id_to_list_index_map.end() == m_edge_id_to_list_index_map.find(edge_id_2) ); + BOOST_ASSERT(m_edge_id_to_list_index_map.end() == + m_edge_id_to_list_index_map.find(edge_id_2)); edge_bucket_list2.clear(); - BOOST_ASSERT( 0 == edge_bucket_list2.size() ); + BOOST_ASSERT(0 == edge_bucket_list2.size()); m_free_list.push_back(list_to_remove_index); - BOOST_ASSERT( list_to_remove_index == m_free_list.back() ); + BOOST_ASSERT(list_to_remove_index == m_free_list.back()); } else { // we are certain that the second edge is atomic. - edge_bucket_list1.push_back( std::make_pair(target_node_id, weight2) ); + edge_bucket_list1.push_back(std::make_pair(target_node_id, weight2)); } } @@ -216,28 +196,31 @@ void GeometryCompressor::PrintStatistics() const { const uint64_t compressed_edges = m_compressed_geometries.size(); BOOST_ASSERT(0 == compressed_edges % 2); - BOOST_ASSERT( m_compressed_geometries.size() + m_free_list.size() > 0 ); + BOOST_ASSERT(m_compressed_geometries.size() + m_free_list.size() > 0); uint64_t number_of_compressed_geometries = 0; uint64_t longest_chain_length = 0; - BOOST_FOREACH(const std::vector & current_vector, m_compressed_geometries) + BOOST_FOREACH (const std::vector ¤t_vector, m_compressed_geometries) { number_of_compressed_geometries += current_vector.size(); longest_chain_length = std::max(longest_chain_length, (uint64_t)current_vector.size()); } SimpleLogger().Write() << "Geometry successfully removed:" - "\n compressed edges: " << compressed_edges << - "\n compressed geometries: " << number_of_compressed_geometries << - "\n longest chain length: " << longest_chain_length << - "\n cmpr ratio: " << ((float)compressed_edges/std::max(number_of_compressed_geometries, (uint64_t)1) ) << - "\n avg chain length: " << (float)number_of_compressed_geometries/std::max((uint64_t)1, compressed_edges); + "\n compressed edges: " << compressed_edges + << "\n compressed geometries: " << number_of_compressed_geometries + << "\n longest chain length: " << longest_chain_length + << "\n cmpr ratio: " + << ((float)compressed_edges / + std::max(number_of_compressed_geometries, (uint64_t)1)) + << "\n avg chain length: " + << (float)number_of_compressed_geometries / + std::max((uint64_t)1, compressed_edges); } -const std::vector & GeometryCompressor::GetBucketReference( - const EdgeID edge_id -) const +const std::vector & +GeometryCompressor::GetBucketReference(const EdgeID edge_id) const { - const unsigned index = m_edge_id_to_list_index_map.at( edge_id ); - return m_compressed_geometries.at( index ); + const unsigned index = m_edge_id_to_list_index_map.at(edge_id); + return m_compressed_geometries.at(index); } diff --git a/Contractor/GeometryCompressor.h b/Contractor/GeometryCompressor.h index 7d3593dc3..39c92d45d 100644 --- a/Contractor/GeometryCompressor.h +++ b/Contractor/GeometryCompressor.h @@ -28,38 +28,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../typedefs.h" #include -#include #include #ifndef GEOMETRY_COMPRESSOR_H #define GEOMETRY_COMPRESSOR_H -class GeometryCompressor { -public: +class GeometryCompressor +{ + public: typedef std::pair CompressedNode; GeometryCompressor(); - void CompressEdge( - const EdgeID surviving_edge_id, - const EdgeID removed_edge_id, - const NodeID via_node_id, - const NodeID target_node, - const EdgeWeight weight1, - const EdgeWeight weight2 - ); + void CompressEdge(const EdgeID surviving_edge_id, + const EdgeID removed_edge_id, + const NodeID via_node_id, + const NodeID target_node, + const EdgeWeight weight1, + const EdgeWeight weight2); bool HasEntryForID(const EdgeID edge_id) const; void PrintStatistics() const; - void SerializeInternalVector(const std::string & path) const; + void SerializeInternalVector(const std::string &path) const; unsigned GetPositionForID(const EdgeID edge_id) const; - const std::vector & GetBucketReference(const EdgeID edge_id) const; + const std::vector & + GetBucketReference(const EdgeID edge_id) const; -private: + private: void IncreaseFreeList(); std::vector > m_compressed_geometries; std::vector m_free_list; boost::unordered_map m_edge_id_to_list_index_map; }; -#endif //GEOMETRY_COMPRESSOR_H +#endif // GEOMETRY_COMPRESSOR_H From d09be5a80ea4ac24c838faa9e3f9484bba5a39d7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 16:26:10 -0400 Subject: [PATCH 60/89] remove debug code, make variables const --- Server/DataStructures/InternalDataFacade.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 0e6769864..a18b93a28 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -395,12 +395,10 @@ public: FixedPointCoordinate GetCoordinateOfNode( const unsigned id ) const { - // const unsigned coordinate_index = m_via_node_list.at(id); return m_coordinate_list->at(id); }; bool EdgeIsCompressed( const unsigned id ) const { - // const NodeID node = m_via_node_list.at(id); return m_egde_is_compressed.at(id); } @@ -427,7 +425,6 @@ public: PhantomNode & resulting_phantom_node, const unsigned zoom_level ) const { - // SimpleLogger().Write(logDEBUG) << "name id: " << resulting_phantom_node.name_id; const bool found = m_static_rtree->FindPhantomNodeForCoordinate( input_coordinate, resulting_phantom_node, @@ -451,8 +448,8 @@ public: 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]; + const unsigned begin_index = m_name_begin_indices[name_id]; + const 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" From fa047064848984b110322a25d0140c8c914a9b7b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 16:26:56 -0400 Subject: [PATCH 61/89] remove debug code, add C++11 todo --- Contractor/EdgeBasedGraphFactory.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index f4575a656..b067e6b2f 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -423,15 +423,12 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( !reverse_data.forward ); } - // BOOST_ASSERT( forward_data.forward == reverse_data.backward ); - // BOOST_ASSERT( reverse_data.forward == forward_data.backward ); - BOOST_ASSERT( forward_data.edgeBasedNodeID != SPECIAL_NODEID || reverse_data.edgeBasedNodeID != SPECIAL_NODEID ); - //TODO: emplace_back with C++11 + //TODO C++11: emplace_back with m_edge_based_node_list.push_back( EdgeBasedNode( forward_data.edgeBasedNodeID, From 5d93c687905909432a65d49e9df5c1a26fe612f2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 11 Apr 2014 16:48:55 -0400 Subject: [PATCH 62/89] remove further debug things --- Contractor/GeometryCompressor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 2115d9b77..53cca3fdf 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -140,11 +140,9 @@ void GeometryCompressor::CompressEdge(const EdgeID edge_id_1, if (0 == m_free_list.size()) { // make sure there is a place to put the entries - // SimpleLogger().Write() << "increased free list"; IncreaseFreeList(); } BOOST_ASSERT(!m_free_list.empty()); - // SimpleLogger().Write() << "free list size: " << m_free_list.size(); m_edge_id_to_list_index_map[edge_id_1] = m_free_list.back(); m_free_list.pop_back(); } From f468fcc2b613b484251aefc9725b016eacbd343b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Wed, 16 Apr 2014 19:36:42 +0200 Subject: [PATCH 63/89] implement more details of shared memory store --- Server/DataStructures/SharedDataType.h | 5 +++-- datastore.cpp | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index a2bcdbc0c..6724b0ea6 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -97,9 +97,9 @@ struct SharedDataLayout { 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) << "geometries_compression: " << geometries_compression; + SimpleLogger().Write(logDEBUG) << "geometries_compression: " << geometries_compression << "/" << ((geometries_compression/32) + 1); SimpleLogger().Write(logDEBUG) << "geometries_index_list_size: " << geometries_index_list_size; - SimpleLogger().Write(logDEBUG) << "geometry_list_size: " << geometries_list_size; + SimpleLogger().Write(logDEBUG) << "geometries_list_size: " << geometries_list_size; SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); SimpleLogger().Write(logDEBUG) << "ram index file name: " << ram_index_file_name; } @@ -116,6 +116,7 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + + (geometries_compression/32) + 1 + (geometries_index_list_size * sizeof(unsigned) ) + (geometries_list_size * sizeof(unsigned) ) + sizeof(checksum) + diff --git a/datastore.cpp b/datastore.cpp index 8d3dccd8d..3c2f55048 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -287,11 +287,9 @@ int main( const int argc, const char * argv[] ) { // read actual data into shared memory object // // Loading street names - // SimpleLogger().Write() << "Loading names index and chars from: " << names_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, From 7a6a5f6612bc6f78deca9227cef44a8cab3b8680 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 17 Apr 2014 12:13:23 +0200 Subject: [PATCH 64/89] implement population of shared vector overload (manually, yikes) --- DataStructures/SharedMemoryVectorWrapper.h | 8 ++++++-- datastore.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 536a7c5e2..78a77218e 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -82,7 +82,9 @@ public: SharedMemoryWrapper(DataT * ptr, std::size_t size) : m_ptr(ptr), m_size(size) - { } + { + SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << size; + } void swap( SharedMemoryWrapper & other ) { BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid"); @@ -143,7 +145,9 @@ public: SharedMemoryWrapper(unsigned * ptr, std::size_t size) : m_ptr(ptr), m_size(size) - { } + { + SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << size; + } void swap( SharedMemoryWrapper & other ) { BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid"); diff --git a/datastore.cpp b/datastore.cpp index 3c2f55048..3cfe295e3 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -192,6 +192,7 @@ int main( const int argc, const char * argv[] ) { 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; + shared_layout_ptr->geometries_compression = number_of_original_edges; boost::filesystem::ifstream hsgr_input_stream( hsgr_path, @@ -316,6 +317,10 @@ int main( const int argc, const char * argv[] ) { shared_memory_ptr + shared_layout_ptr->GetTurnInstructionListOffset() ); + unsigned * geometries_index_ptr = (unsigned *)( + shared_memory + shared_layout_ptr->GetGeometriesIndicesOffset() + ); + OriginalEdgeData current_edge_data; for(unsigned i = 0; i < number_of_original_edges; ++i) { // SimpleLogger().Write() << i << "/" << number_of_edges; @@ -326,6 +331,11 @@ int main( const int argc, const char * argv[] ) { via_node_ptr[i] = current_edge_data.via_node; name_id_ptr[i] = current_edge_data.name_id; turn_instructions_ptr[i] = current_edge_data.turn_instruction; + + const unsigned bucket = i / 32; + const unsigned offset = i % 32; + geometries_index_ptr[bucket] |= (1 << offset); + } edges_input_stream.close(); From 9b3dab8055fb0109c43b1d1ed44b771e3e85e652 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 17 Apr 2014 16:59:08 +0200 Subject: [PATCH 65/89] implement loading of compressed geometries --- DataStructures/SharedMemoryVectorWrapper.h | 6 ++- Descriptors/DescriptionFactory.cpp | 16 +++---- Server/DataStructures/SharedDataFacade.h | 4 +- Server/DataStructures/SharedDataType.h | 21 ++++++--- datastore.cpp | 50 ++++++++++++++++++++-- 5 files changed, 75 insertions(+), 22 deletions(-) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 78a77218e..6a42c836d 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -140,13 +140,15 @@ public: SharedMemoryWrapper() : m_ptr(NULL), m_size(0) - { } + { + SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << m_size; + } SharedMemoryWrapper(unsigned * ptr, std::size_t size) : m_ptr(ptr), m_size(size) { - SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << size; + SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << m_size; } void swap( SharedMemoryWrapper & other ) { diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index 45cc584da..be69d5fb8 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -68,10 +68,10 @@ double DescriptionFactory::GetBearing(const FixedPointCoordinate & A, const Fixe void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool source_traversed_in_reverse) { - int fwd_weight = source.forward_weight; - int rev_weight = source.reverse_weight; - int fwd_offset = source.forward_offset; - int rev_offset = source.reverse_offset; + // int fwd_weight = source.forward_weight; + // int rev_weight = source.reverse_weight; + // int fwd_offset = source.forward_offset; + // int rev_offset = source.reverse_offset; // SimpleLogger().Write(logDEBUG) << "df source, traversed in reverse: " << (source_traversed_in_reverse ? "y" : "n") << ", location: " << source.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; // SimpleLogger().Write(logDEBUG) << "duration of first segment: " << (source_traversed_in_reverse ? source.GetReverseWeightPlusOffset() : source.GetForwardWeightPlusOffset()); start_phantom = source; @@ -83,10 +83,10 @@ void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool void DescriptionFactory::SetEndSegment(const PhantomNode & target, const bool target_traversed_in_reverse) { - int fwd_weight = target.forward_weight; - int rev_weight = target.reverse_weight; - int fwd_offset = target.forward_offset; - int rev_offset = target.reverse_offset; + // int fwd_weight = target.forward_weight; + // int rev_weight = target.reverse_weight; + // int fwd_offset = target.forward_offset; + // int rev_offset = target.reverse_offset; // SimpleLogger().Write(logDEBUG) << "df target, traversed in reverse: " << (target_traversed_in_reverse ? "y" : "n") << ", location: " << target.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; // SimpleLogger().Write(logDEBUG) << "duration of last segment: " << (target_traversed_in_reverse ? target.GetReverseWeightPlusOffset() : target.GetForwardWeightPlusOffset()); diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 31ec27a66..5d7fe6310 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -210,7 +210,7 @@ private: void LoadGeometries() { unsigned * geometries_compressed_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometriesCompressedOffset() + shared_memory + data_layout->GetGeometriesIndexListOffset() ); typename ShM::vector egde_is_compressed( geometries_compressed_ptr, @@ -219,7 +219,7 @@ private: m_egde_is_compressed.swap(egde_is_compressed); unsigned * geometries_index_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometriesIndicesOffset() + shared_memory + data_layout->GetGeometriesIndicatorOffset() ); typename ShM::vector geometry_begin_indices( geometries_index_ptr, diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 6724b0ea6..388374bd7 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -116,11 +116,12 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32) + 1 + + (geometries_compression/32 + 1) * sizeof(unsigned) + (geometries_index_list_size * sizeof(unsigned) ) + (geometries_list_size * sizeof(unsigned) ) + sizeof(checksum) + 1024*sizeof(char); + PrintInformation(); return result; } @@ -170,6 +171,7 @@ struct SharedDataLayout { (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)); + SimpleLogger().Write(logDEBUG) << "GetTimeStampOffset: " << result; return result; } uint64_t GetCoordinateListOffset() const { @@ -181,6 +183,7 @@ struct SharedDataLayout { (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + (timestamp_length * sizeof(char) ); + SimpleLogger().Write(logDEBUG) << "GetCoordinateListOffset: " << result; return result; } uint64_t GetTurnInstructionListOffset() const { @@ -193,6 +196,7 @@ struct SharedDataLayout { (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + (timestamp_length * sizeof(char) ) + (coordinate_list_size * sizeof(FixedPointCoordinate)); + SimpleLogger().Write(logDEBUG) << "GetTurnInstructionListOffset: " << result; return result; } uint64_t GetRSearchTreeOffset() const { @@ -206,9 +210,10 @@ struct SharedDataLayout { (timestamp_length * sizeof(char) ) + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)); + SimpleLogger().Write(logDEBUG) << "GetRSearchTreeOffset: " << result; return result; } - uint64_t GetGeometriesIndicesOffset() const { + uint64_t GetGeometriesIndicatorOffset() const { uint64_t result = (name_index_list_size * sizeof(unsigned) ) + (name_char_list_size * sizeof(char) ) + @@ -220,10 +225,11 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ); + SimpleLogger().Write(logDEBUG) << "GetGeometriesIndicatorOffset: " << result; return result; } - uint64_t GetGeometriesCompressedOffset() const + uint64_t GetGeometriesIndexListOffset() const { uint64_t result = (name_index_list_size * sizeof(unsigned) ) + @@ -236,7 +242,8 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32) + 1; + (geometries_compression/32 + 1) * sizeof(unsigned); + SimpleLogger().Write(logDEBUG) << "GetGeometriesCompressedOffset: " << result; return result; } @@ -252,8 +259,9 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32) + 1 + + (geometries_compression/32 + 1) * sizeof(unsigned) + (geometries_index_list_size * sizeof(unsigned) ); + SimpleLogger().Write(logDEBUG) << "GetGeometryListOffset: " << result; return result; } uint64_t GetChecksumOffset() const { @@ -268,9 +276,10 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32) + 1 + + (geometries_compression/32 + 1) * sizeof(unsigned) + (geometries_index_list_size * sizeof(unsigned) ) + (geometries_list_size * sizeof(unsigned) ); + SimpleLogger().Write(logDEBUG) << "GetChecksumOffset: " << result; return result; } }; diff --git a/datastore.cpp b/datastore.cpp index 3cfe295e3..131d97f0e 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -44,8 +44,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #endif -#include #include +#include +#include #include #include @@ -137,6 +138,10 @@ int main( const int argc, const char * argv[] ) { BOOST_ASSERT(!paths_iterator->second.empty()); const boost::filesystem::path & names_data_path = paths_iterator->second; + paths_iterator = server_paths.find("geometries"); + BOOST_ASSERT(server_paths.end() != paths_iterator); + BOOST_ASSERT(!paths_iterator->second.empty()); + const boost::filesystem::path & geometries_data_path = paths_iterator->second; // get the shared memory segment to use bool use_first_segment = SharedMemory::RegionExists( LAYOUT_2 ); @@ -277,6 +282,22 @@ int main( const int argc, const char * argv[] ) { shared_layout_ptr->coordinate_list_size = coordinate_list_size; + // load geometries sizes + boost::filesystem::ifstream geometry_input_stream( + geometries_data_path, + std::ios::binary + ); + unsigned number_of_geometries_indices = 0; + unsigned number_of_compressed_geometries = 0; + + geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned)); + shared_layout_ptr->geometries_index_list_size = number_of_geometries_indices; + boost::iostreams::seek(geometry_input_stream, number_of_geometries_indices*sizeof(unsigned), BOOST_IOS::cur); + geometry_input_stream.read( (char *)&number_of_compressed_geometries, sizeof(unsigned)); + shared_layout_ptr->geometries_list_size = number_of_compressed_geometries; + + SimpleLogger().Write(logDEBUG) << "number_of_geometries_indices : " << number_of_geometries_indices << ", number_of_compressed_geometries: " << number_of_compressed_geometries; + // allocate shared memory block SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes"; @@ -317,8 +338,8 @@ int main( const int argc, const char * argv[] ) { shared_memory_ptr + shared_layout_ptr->GetTurnInstructionListOffset() ); - unsigned * geometries_index_ptr = (unsigned *)( - shared_memory + shared_layout_ptr->GetGeometriesIndicesOffset() + unsigned * geometries_indicator_ptr = (unsigned *)( + shared_memory_ptr + shared_layout_ptr->GetGeometriesIndicatorOffset() ); OriginalEdgeData current_edge_data; @@ -334,11 +355,32 @@ int main( const int argc, const char * argv[] ) { const unsigned bucket = i / 32; const unsigned offset = i % 32; - geometries_index_ptr[bucket] |= (1 << offset); + unsigned value = ((0 == offset) ? 0 : geometries_indicator_ptr[bucket]); + geometries_indicator_ptr[bucket] = (value | (1 << offset)); } edges_input_stream.close(); + //TODO: load compressed geometry + + unsigned * geometries_index_ptr = (unsigned *)( + shared_memory_ptr + shared_layout_ptr->GetGeometriesIndexListOffset() + ); + boost::iostreams::seek(geometry_input_stream, sizeof(unsigned), BOOST_IOS::beg); + geometry_input_stream.read( + (char *)geometries_index_ptr, + shared_layout_ptr->geometries_index_list_size*sizeof(unsigned) + ); + + unsigned * geometries_list_ptr = (unsigned *)( + shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset() + ); + boost::iostreams::seek(geometry_input_stream, sizeof(unsigned), BOOST_IOS::cur); + geometry_input_stream.read( + (char *)geometries_list_ptr, + shared_layout_ptr->geometries_list_size*sizeof(unsigned) + ); + // Loading list of coordinates FixedPointCoordinate * coordinates_ptr = (FixedPointCoordinate *)( shared_memory_ptr + shared_layout_ptr->GetCoordinateListOffset() From 18861d58b5f2e922819b258cd4dfc830fc1562e4 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 18 Apr 2014 13:54:21 +0200 Subject: [PATCH 66/89] compile fix for linux / wrong include --- Util/SimpleLogger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Util/SimpleLogger.h b/Util/SimpleLogger.h index 00b893579..ecba27b68 100644 --- a/Util/SimpleLogger.h +++ b/Util/SimpleLogger.h @@ -32,7 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include #include From 2c9edcaf23114656c41a6510069b1582d70adfad Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 18 Apr 2014 13:54:34 +0200 Subject: [PATCH 67/89] remove debug code --- Descriptors/JSONDescriptor.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 390422c78..e4aad4192 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -129,22 +129,6 @@ public: return; } - // std::string name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); - int fwd_weight = phantom_nodes.source_phantom.forward_weight; - int rev_weight = phantom_nodes.source_phantom.reverse_weight; - int fwd_offset = phantom_nodes.source_phantom.forward_offset; - int rev_offset = phantom_nodes.source_phantom.reverse_offset; - // SimpleLogger().Write(logDEBUG) << "json source: " << name << ", location: " << phantom_nodes.source_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - // name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); - fwd_weight = phantom_nodes.target_phantom.forward_weight; - rev_weight = phantom_nodes.target_phantom.reverse_weight; - fwd_offset = phantom_nodes.target_phantom.forward_offset; - rev_offset = phantom_nodes.target_phantom.reverse_offset; - // SimpleLogger().Write(logDEBUG) << "json target: " << name << ", location: " << phantom_nodes.target_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - - - //TODO: replace the previous logic with this one. - //check if first segment is non-zero std::string road_name; int source_duration = phantom_nodes.source_phantom.GetForwardWeightPlusOffset(); @@ -155,29 +139,18 @@ public: } BOOST_ASSERT(source_duration >= 0); road_name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); - // if (source_duration > 0) - // { - // SimpleLogger().Write(logDEBUG) << "adding source \"" << road_name << "\" at " << phantom_nodes.source_phantom.location << ", duration: " << source_duration; - // } - // else - // { - // SimpleLogger().Write(logDEBUG) << "ignoring source \"" << road_name << "\""; - // } - // TODO, for each unpacked segment add the leg to the description + // for each unpacked segment add the leg to the description BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() ); for (unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i) { const std::vector & leg_path = raw_route.unpacked_path_segments[i]; - // const PhantomNodes & leg_phantoms = raw_route.segmentEndCoordinates[i]; - // SimpleLogger().Write(logDEBUG) << " Describing leg from " << leg_phantoms.source_phantom.location << " and " << leg_phantoms.target_phantom.location; FixedPointCoordinate current_coordinate; BOOST_FOREACH(const PathData & path_data, leg_path) { current_coordinate = facade->GetCoordinateOfNode(path_data.node); road_name = facade->GetEscapedNameForNameID(path_data.name_id); - // SimpleLogger().Write(logDEBUG) << " adding way point for \"" << road_name << "\" at " << current_coordinate << ", duration: " << path_data.durationOfSegment; } } From edef9c11f75e50988b155fd4a665bbb6491beed3 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 18 Apr 2014 14:12:56 +0200 Subject: [PATCH 68/89] add default clause to switch statement albeit technically superflous --- Server/RequestParser.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Server/RequestParser.cpp b/Server/RequestParser.cpp index 256fa5f0e..8b2b1a985 100644 --- a/Server/RequestParser.cpp +++ b/Server/RequestParser.cpp @@ -239,6 +239,8 @@ boost::tribool RequestParser::consume( } case expecting_newline_3: return (input == '\n'); + default: + return false; } } From 2435fadfbddd1958c58d1cffc83777add25f1523 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 18 Apr 2014 14:13:29 +0200 Subject: [PATCH 69/89] use boost filesystem specialization instead of the ones from std --- prepare.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/prepare.cpp b/prepare.cpp index f21b3c566..3161f86a7 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -45,13 +45,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "typedefs.h" #include +#include +#include #include -#include -#include -#include -#include #include #include @@ -158,7 +156,7 @@ int main (int argc, char *argv[]) { omp_set_num_threads( std::min( omp_get_num_procs(), requested_num_threads) ); LogPolicy::GetInstance().Unmute(); - std::ifstream restrictionsInstream( restrictions_path.c_str(), std::ios::binary); + boost::filesystem::ifstream restrictionsInstream(restrictions_path, std::ios::binary); TurnRestriction restriction; UUID uuid_loaded, uuid_orig; unsigned usableRestrictionsCounter(0); @@ -180,8 +178,8 @@ int main (int argc, char *argv[]) { ); restrictionsInstream.close(); - std::ifstream in; - in.open(input_path.c_str(), std::ifstream::in|std::ifstream::binary); + boost::filesystem::ifstream in; + in.open(input_path, std::ios::in|std::ios::binary); const std::string nodeOut = input_path.string() + ".nodes"; const std::string edgeOut = input_path.string() + ".edges"; @@ -295,7 +293,7 @@ int main (int argc, char *argv[]) { */ SimpleLogger().Write() << "writing node map ..."; - std::ofstream mapOutFile(nodeOut, std::ios::binary); + boost::filesystem::ofstream mapOutFile(nodeOut, std::ios::binary); const unsigned size_of_mapping = internalToExternalNodeMapping.size(); mapOutFile.write((char *)&size_of_mapping, sizeof(unsigned)); mapOutFile.write( @@ -335,7 +333,7 @@ int main (int argc, char *argv[]) { contracted_edge_count << " edges"; - std::ofstream hsgr_output_stream(graphOut, std::ios::binary); + boost::filesystem::ofstream hsgr_output_stream(graphOut, std::ios::binary); hsgr_output_stream.write((char*)&uuid_orig, sizeof(UUID) ); BOOST_FOREACH(const QueryEdge & edge, contractedEdgeList) { From 09dc21af3133a5735945a3df75de6b44608e9efa Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 18 Apr 2014 16:00:51 +0200 Subject: [PATCH 70/89] remove debug lint --- prepare.cpp | 95 +++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 64 deletions(-) diff --git a/prepare.cpp b/prepare.cpp index 3161f86a7..631e61efb 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -181,12 +181,12 @@ int main (int argc, char *argv[]) { boost::filesystem::ifstream in; in.open(input_path, std::ios::in|std::ios::binary); - const std::string nodeOut = input_path.string() + ".nodes"; - const std::string edgeOut = input_path.string() + ".edges"; + const std::string nodeOut = input_path.string() + ".nodes"; + const std::string edgeOut = input_path.string() + ".edges"; const std::string geometry_filename = input_path.string() + ".geometry"; - const std::string graphOut = input_path.string() + ".hsgr"; - const std::string rtree_nodes_path = input_path.string() + ".ramIndex"; - const std::string rtree_leafs_path = input_path.string() + ".fileIndex"; + const std::string graphOut = input_path.string() + ".hsgr"; + const std::string rtree_nodes_path = input_path.string() + ".ramIndex"; + const std::string rtree_leafs_path = input_path.string() + ".fileIndex"; /*** Setup Scripting Environment ***/ @@ -269,10 +269,9 @@ int main (int argc, char *argv[]) { delete edgeBasedGraphFactory; double expansionHasFinishedTime = get_timestamp() - startupTime; - /*** - * Building grid-like nearest-neighbor data structure - */ + + // Building grid-like nearest-neighbor data structure SimpleLogger().Write() << "building r-tree ..."; StaticRTree * rtree = new StaticRTree( @@ -355,20 +354,17 @@ int main (int argc, char *argv[]) { StaticGraph::EdgeIterator position = 0; StaticGraph::EdgeIterator lastEdge = edge; - for ( StaticGraph::NodeIterator node = 0; node < max_used_node_id; ++node ) { + for ( StaticGraph::NodeIterator node = 0; node < max_used_node_id; ++node) + { lastEdge = edge; - while ( edge < contracted_edge_count && contractedEdgeList[edge].source == node ) + while ((edge < contracted_edge_count) && (contractedEdgeList[edge].source == node)) { ++edge; } node_array[node].firstEdge = position; //=edge position += edge - lastEdge; //remove - // SimpleLogger().Write(logDEBUG) << "node: " << node << ", edge: " << edge << ", position: " << position << ", lastEdge: " << lastEdge; } - // SimpleLogger().Write(logDEBUG) << "contracted_edge_count: " << contracted_edge_count << ", position: " << position << ", lastEdge: " << lastEdge; - // SimpleLogger().Write(logDEBUG) << "marking range [" << max_used_node_id << "," << node_array.size() << ") as dummies"; - for (unsigned sentinel_counter = max_used_node_id; sentinel_counter != node_array.size(); ++sentinel_counter @@ -376,23 +372,9 @@ int main (int argc, char *argv[]) { { //sentinel element, guarded against underflow node_array[sentinel_counter].firstEdge = contracted_edge_count; - // SimpleLogger().Write(logDEBUG) << "node_array[" << sentinel_counter << "].firstEdge = " << node_array[sentinel_counter].firstEdge; } - // node_array.back().firstEdge = contracted_edge_count; //sentinel element - // ++max_used_node_id; - - // BOOST_ASSERT_MSG( - // node_array.size() == max_used_node_id, - // "no. of nodes dont match" - // ); - - // for(unsigned i = 0; i < node_array.size(); ++i) - // { - // SimpleLogger().Write() << "node_array[" << i << "].firstEdge = " << node_array[i].firstEdge; - // } unsigned node_array_size = node_array.size(); - //serialize crc32, aka checksum hsgr_output_stream.write((char*) &crc32OfNodeBasedEdgeList, sizeof(unsigned)); //serialize number of nodes @@ -407,43 +389,30 @@ int main (int argc, char *argv[]) { edge = 0; int usedEdgeCounter = 0; - for(unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) - { - // SimpleLogger().Write(logDEBUG) << ">[" << edge << "] (" << contractedEdgeList[edge].source << "," << contractedEdgeList[edge].target << ")"; - } - StaticGraph::_StrEdge currentEdge; - for(unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) + for (unsigned edge = 0; edge < contractedEdgeList.size(); ++edge) { - // for ( StaticGraph::NodeIterator node = 0; node < max_used_node_id; ++node ) { - // for ( StaticGraph::EdgeIterator i = node_array[node].firstEdge, e = node_array[node+1].firstEdge; i != e; ++i ) { - // BOOST_ASSERT(node == contractedEdgeList[edge].source) - // no eigen loops - BOOST_ASSERT(contractedEdgeList[edge].source != contractedEdgeList[edge].target); - currentEdge.target = contractedEdgeList[edge].target; - currentEdge.data = contractedEdgeList[edge].data; + // no eigen loops + BOOST_ASSERT(contractedEdgeList[edge].source != contractedEdgeList[edge].target); + currentEdge.target = contractedEdgeList[edge].target; + currentEdge.data = contractedEdgeList[edge].data; - // every target needs to be valid - BOOST_ASSERT(currentEdge.target < max_used_node_id); - if(currentEdge.data.distance <= 0) { - SimpleLogger().Write(logWARNING) << - "Edge: " << edge << - ",source: " << contractedEdgeList[edge].source << - ", target: " << contractedEdgeList[edge].target << - ", dist: " << currentEdge.data.distance; + // every target needs to be valid + BOOST_ASSERT(currentEdge.target < max_used_node_id); + if(currentEdge.data.distance <= 0) { + SimpleLogger().Write(logWARNING) << + "Edge: " << edge << + ",source: " << contractedEdgeList[edge].source << + ", target: " << contractedEdgeList[edge].target << + ", dist: " << currentEdge.data.distance; - SimpleLogger().Write(logWARNING) << - "Failed at adjacency list of node " << contractedEdgeList[edge].source << "/" << node_array.size()-1; - return 1; - } - //Serialize edges - // SimpleLogger().Write(logDEBUG) << "edge[" << edge << "], (" << contractedEdgeList[edge].source << "," << currentEdge.target << "), w: " << currentEdge.data.distance << - // "shortcut: " << (currentEdge.data.shortcut ? "y" : "n"); - hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); - // ++edge; - ++usedEdgeCounter; + SimpleLogger().Write(logWARNING) << + "Failed at adjacency list of node " << contractedEdgeList[edge].source << "/" << node_array.size()-1; + return 1; } - // } + hsgr_output_stream.write((char*) ¤tEdge, sizeof(StaticGraph::_StrEdge)); + ++usedEdgeCounter; + } hsgr_output_stream.close(); SimpleLogger().Write() << "Preprocessing : " << @@ -456,7 +425,6 @@ int main (int argc, char *argv[]) { (edgeBasedNodeNumber/contraction_duration) << " nodes/sec and " << usedEdgeCounter/contraction_duration << " edges/sec"; - //cleanedEdgeList.clear(); node_array.clear(); SimpleLogger().Write() << "finished preprocessing"; } catch(boost::program_options::too_many_positional_options_error&) { @@ -466,9 +434,8 @@ int main (int argc, char *argv[]) { SimpleLogger().Write(logWARNING) << e.what(); return 1; } catch ( const std::exception &e ) { - SimpleLogger().Write(logWARNING) << - "Exception occured: " << e.what() << std::endl; - return 1; + SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl; + return -1; } return 0; } From d0e158ca07348231e235d017733ef1878ad89613 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:10:10 +0200 Subject: [PATCH 71/89] fix unpacking of geometry for shared memory --- DataStructures/SharedMemoryVectorWrapper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 6a42c836d..8049abae5 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -165,7 +165,7 @@ public: // } bool at(const std::size_t index) const { - BOOST_ASSERT_MSG(index < m_size, "invalid size"); + // BOOST_ASSERT_MSG(index < m_size, "invalid size"); const unsigned bucket = index / 32; const unsigned offset = index % 32; return m_ptr[bucket] & (1 << offset); From ede5cca2e7432a307117ded8508220ce797b9505 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:11:52 +0200 Subject: [PATCH 72/89] fix unpacking of geometry for shared memory --- Descriptors/DescriptionFactory.h | 6 ------ Descriptors/JSONDescriptor.h | 14 -------------- 2 files changed, 20 deletions(-) diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index 3d5f49bb6..ed22a11cb 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -112,12 +112,6 @@ public: pathDescription[i].length = FixedPointCoordinate::ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location); } - for (unsigned i = 0; i < pathDescription.size(); ++i) - { - const std::string name = facade->GetEscapedNameForNameID(pathDescription[0].name_id); - // SimpleLogger().Write(logDEBUG) << "df [" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location; - } - /*Simplify turn instructions Input : 10. Turn left on B 36 for 20 km diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index e4aad4192..9b6985b4f 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -132,7 +132,6 @@ public: //check if first segment is non-zero std::string road_name; int source_duration = phantom_nodes.source_phantom.GetForwardWeightPlusOffset(); - // SimpleLogger().Write(logDEBUG) << "-> source_traversed_in_reverse: " << (raw_route.source_traversed_in_reverse ? "y" : "n"); if (!raw_route.source_traversed_in_reverse) { source_duration = phantom_nodes.source_phantom.GetReverseWeightPlusOffset(); @@ -164,18 +163,6 @@ public: } BOOST_ASSERT(target_duration >= 0); - // if (target_duration > 0) - // { - // SimpleLogger().Write(logDEBUG) << "adding target \"" << road_name << "\" at " << phantom_nodes.target_phantom.location << ", duration: " << target_duration; - // } - // else - // { - // SimpleLogger().Write(logDEBUG) << "ignoring target \"" << road_name << "\""; - // } - // SimpleLogger().Write(logDEBUG) << "-> target_traversed_in_reverse: " << (raw_route.target_traversed_in_reverse ? "y" : "n"); - - //END OF TODO - description_factory.SetStartSegment(phantom_nodes.source_phantom, raw_route.source_traversed_in_reverse); reply.content.push_back("0," "\"status_message\": \"Found route between points\","); @@ -244,7 +231,6 @@ public: //only one alternative route is computed at this time, so this is hardcoded - if(raw_route.lengthOfAlternativePath != INVALID_EDGE_WEIGHT) { alternate_descriptionFactory.SetStartSegment(phantom_nodes.source_phantom, raw_route.alt_source_traversed_in_reverse); From 8b3002a68529825f01fce595e9a333d62a21cb07 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:13:30 +0200 Subject: [PATCH 73/89] fix unpacking of geometry for shared memory --- Plugins/ViaRoutePlugin.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 6242f172e..007cdae29 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -95,14 +95,11 @@ public: std::vector phantomNodeVector(rawRoute.rawViaNodeCoordinates.size()); for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); ++i) { if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) { -// SimpleLogger().Write() <<"Decoding hint: " << routeParameters.hints[i] << " for location index " << i; DecodeObjectFromBase64(routeParameters.hints[i], phantomNodeVector[i]); if(phantomNodeVector[i].isValid(facade->GetNumberOfNodes())) { -// SimpleLogger().Write() << "Decoded hint " << i << " successfully"; continue; } } -// SimpleLogger().Write() << "Brute force lookup of coordinate " << i; facade->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i], @@ -132,9 +129,9 @@ public: ); } - if(INT_MAX == rawRoute.lengthOfShortestPath ) { - SimpleLogger().Write(logDEBUG) << - "Error occurred, single path not found"; + if (INT_MAX == rawRoute.lengthOfShortestPath) + { + SimpleLogger().Write(logDEBUG) << "Error occurred, single path not found"; } reply.status = http::Reply::ok; @@ -177,6 +174,7 @@ public: desc->SetConfig(descriptorConfig); desc->Run(rawRoute, phantomNodes, facade, reply); + if("" != routeParameters.jsonpParameter) { reply.content.push_back(")\n"); } From 5da01946b842852a8ad27cf5b91703fc8f4d4ed7 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:15:38 +0200 Subject: [PATCH 74/89] fix unpacking of geometry for shared memory --- RoutingAlgorithms/BasicRoutingInterface.h | 33 +---------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 5efe5279e..04913a38e 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -67,11 +67,9 @@ public: { const NodeID node = forward_heap.DeleteMin(); const int distance = forward_heap.GetKey(node); - // SimpleLogger().Write() << (forward_direction ? "fwd" : "rev") << " settled (" << forward_heap.GetData( node ).parent << "," << node << ")=" << distance; if (reverse_heap.WasInserted(node)) { const int new_distance = reverse_heap.GetKey(node) + distance; - // SimpleLogger().Write(logDEBUG) << "new_distance: " << new_distance; if(new_distance < *upper_bound ) { if (new_distance >= 0) @@ -84,7 +82,6 @@ public: if (distance > *upper_bound) { - // SimpleLogger().Write() << "found path"; forward_heap.DeleteAll(); return; } @@ -105,13 +102,12 @@ public: if(forward_heap.WasInserted( to )) { if(forward_heap.GetKey( to ) + edge_weight < distance) { - // SimpleLogger().Write(logDEBUG) << "stalled"; return; } } } } - // SimpleLogger().Write(logDEBUG) << "done stalling"; + for( EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node); edge < end_edge; @@ -150,7 +146,6 @@ public: const PhantomNodes & phantom_node_pair, std::vector & unpacked_path ) const { - // SimpleLogger().Write(logDEBUG) << "packed_path.size: " << packed_path.size(); const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.source_phantom.forward_node_id); const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.target_phantom.forward_node_id); @@ -240,8 +235,6 @@ public: const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1 : phantom_node_pair.source_phantom.fwd_segment_position ) : 0 ); const int end_index = id_vector.size(); std::string name = facade->GetEscapedNameForNameID(name_index); - // SimpleLogger().Write(logDEBUG) << "compressed via segment " << name << " from [" << start_index << "," << end_index << "]"; - BOOST_ASSERT( start_index >= 0 ); BOOST_ASSERT( start_index <= end_index ); @@ -265,44 +258,30 @@ public: } } if(SPECIAL_EDGEID != phantom_node_pair.target_phantom.packed_geometry_id ) { - // SimpleLogger().Write(logDEBUG) << "unpacking last segment " << phantom_node_pair.target_phantom.packed_geometry_id; - // SimpleLogger().Write(logDEBUG) << "start_traversed_in_reverse: " << (start_traversed_in_reverse ? "y" : "n"); - // SimpleLogger().Write(logDEBUG) << "target_traversed_in_reverse: " << (target_traversed_in_reverse ? "y" : "n"); - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.source_phantom.fwd_segment_position: " << phantom_node_pair.source_phantom.fwd_segment_position << ", " << - // "phantom_node_pair.target_phantom.fwd_segment_position: " << phantom_node_pair.target_phantom.fwd_segment_position; std::vector id_vector; facade->GetUncompressedGeometry(phantom_node_pair.target_phantom.packed_geometry_id, id_vector); if( target_traversed_in_reverse ) { std::reverse(id_vector.begin(), id_vector.end() ); } - // SimpleLogger().Write(logDEBUG) << "id_vector.size() " << id_vector.size(); - // SimpleLogger().Write(logDEBUG) << "unpacked_path.empty()=" << (unpacked_path.empty() ? "y" : "n"); - const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id == phantom_node_pair.target_phantom.packed_geometry_id) && unpacked_path.empty(); - // SimpleLogger().Write(logDEBUG) << "is_loc_pl_path: " << (is_local_path ? "y" : "n"); int start_index = 0; int end_index = phantom_node_pair.target_phantom.fwd_segment_position; - // SimpleLogger().Write(logDEBUG) << "case1"; if (target_traversed_in_reverse) { end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position; } if (is_local_path) { - // SimpleLogger().Write(logDEBUG) << "case3"; start_index = phantom_node_pair.source_phantom.fwd_segment_position; end_index = phantom_node_pair.target_phantom.fwd_segment_position; if (target_traversed_in_reverse) { - // SimpleLogger().Write(logDEBUG) << "case4"; start_index = id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position; end_index = id_vector.size() - phantom_node_pair.target_phantom.fwd_segment_position; } } - // SimpleLogger().Write(logDEBUG) << "fetching target segment from [" << start_index << "," << end_index << "]"; - BOOST_ASSERT( start_index >= 0 ); for( int i = start_index; @@ -310,10 +289,6 @@ public: ( start_index < end_index ? ++i :--i) ) { BOOST_ASSERT( i >= -1 ); - if ( i >= 0 ) - { - // SimpleLogger().Write(logDEBUG) << "target [" << i << "]" << facade->GetCoordinateOfNode(id_vector[i]); - } unpacked_path.push_back( PathData( id_vector[i], @@ -324,11 +299,6 @@ public: ); } } - // BOOST_FOREACH(const PathData & path_data, unpacked_path) - // { - // std::string name = facade->GetEscapedNameForNameID(path_data.name_id); - // SimpleLogger().Write(logDEBUG) << "{up} node: " << path_data.node << ", " << facade->GetCoordinateOfNode(path_data.node) << ", name: " << name; - // } // there is no equivalent to a node-based node in an edge-expanded graph. // two equivalent routes may start (or end) at different node-based edges @@ -345,7 +315,6 @@ public: if (unpacked_path[last_index].node == unpacked_path[second_to_last_index].node) { - // SimpleLogger().Write(logDEBUG) << "{rm} node: " << unpacked_path.back().node; unpacked_path.pop_back(); } BOOST_ASSERT(!unpacked_path.empty()); From ca016e2818cdd6f253cc42b3d7d42a0542062228 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:15:59 +0200 Subject: [PATCH 75/89] fix unpacking of geometry for shared memory --- datastore.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/datastore.cpp b/datastore.cpp index 131d97f0e..0b836c3c5 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -48,6 +48,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include @@ -168,7 +169,6 @@ int main( const int argc, const char * argv[] ) { shared_layout_ptr->ram_index_file_name[end_of_string_index] = '\0'; // collect number of elements to store in shared memory object - SimpleLogger().Write(logDEBUG) << "Collecting files sizes"; SimpleLogger().Write() << "load names from: " << names_data_path; // number of entries in name index boost::filesystem::ifstream name_stream( @@ -197,7 +197,7 @@ int main( const int argc, const char * argv[] ) { 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; - shared_layout_ptr->geometries_compression = number_of_original_edges; + shared_layout_ptr->geometries_indicators = number_of_original_edges; boost::filesystem::ifstream hsgr_input_stream( hsgr_path, @@ -283,8 +283,8 @@ int main( const int argc, const char * argv[] ) { // load geometries sizes - boost::filesystem::ifstream geometry_input_stream( - geometries_data_path, + std::ifstream geometry_input_stream( + geometries_data_path.c_str(), std::ios::binary ); unsigned number_of_geometries_indices = 0; @@ -296,10 +296,7 @@ int main( const int argc, const char * argv[] ) { geometry_input_stream.read( (char *)&number_of_compressed_geometries, sizeof(unsigned)); shared_layout_ptr->geometries_list_size = number_of_compressed_geometries; - SimpleLogger().Write(logDEBUG) << "number_of_geometries_indices : " << number_of_geometries_indices << ", number_of_compressed_geometries: " << number_of_compressed_geometries; - // allocate shared memory block - SimpleLogger().Write() << "allocating shared memory of " << shared_layout_ptr->GetSizeOfLayout() << " bytes"; SharedMemory * shared_memory = SharedMemoryFactory::Get( DATA, @@ -356,17 +353,22 @@ int main( const int argc, const char * argv[] ) { const unsigned bucket = i / 32; const unsigned offset = i % 32; unsigned value = ((0 == offset) ? 0 : geometries_indicator_ptr[bucket]); - geometries_indicator_ptr[bucket] = (value | (1 << offset)); - + if (current_edge_data.compressed_geometry) + { + geometries_indicator_ptr[bucket] = (value | (1 << offset)); + } } edges_input_stream.close(); - //TODO: load compressed geometry - + // load compressed geometry + unsigned temporary_value; unsigned * geometries_index_ptr = (unsigned *)( shared_memory_ptr + shared_layout_ptr->GetGeometriesIndexListOffset() ); - boost::iostreams::seek(geometry_input_stream, sizeof(unsigned), BOOST_IOS::beg); + geometry_input_stream.seekg(0, geometry_input_stream.beg); + geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned)); + BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_index_list_size); + geometry_input_stream.read( (char *)geometries_index_ptr, shared_layout_ptr->geometries_index_list_size*sizeof(unsigned) @@ -375,7 +377,10 @@ int main( const int argc, const char * argv[] ) { unsigned * geometries_list_ptr = (unsigned *)( shared_memory_ptr + shared_layout_ptr->GetGeometryListOffset() ); - boost::iostreams::seek(geometry_input_stream, sizeof(unsigned), BOOST_IOS::cur); + + geometry_input_stream.read((char *)&temporary_value, sizeof(unsigned)); + BOOST_ASSERT(temporary_value == shared_layout_ptr->geometries_list_size); + geometry_input_stream.read( (char *)geometries_list_ptr, shared_layout_ptr->geometries_list_size*sizeof(unsigned) @@ -422,7 +427,7 @@ int main( const int argc, const char * argv[] ) { // load the edges of the search graph QueryGraph::_StrEdge * graph_edge_list_ptr = (QueryGraph::_StrEdge *)( - shared_memory_ptr + shared_layout_ptr->GetGraphEdgeListOffsett() + shared_memory_ptr + shared_layout_ptr->GetGraphEdgeListOffset() ); hsgr_input_stream.read( (char*) graph_edge_list_ptr, @@ -473,6 +478,8 @@ int main( const int argc, const char * argv[] ) { } } SimpleLogger().Write() << "all data loaded"; + + shared_layout_ptr->PrintInformation(); } catch(const std::exception & e) { SimpleLogger().Write(logWARNING) << "caught exception: " << e.what(); } From 45f751720a5b914089b124540a79ca27577e2dec Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:17:35 +0200 Subject: [PATCH 76/89] fix unpacking of geometry for shared memory --- Server/DataStructures/InternalDataFacade.h | 8 +--- Server/DataStructures/SharedDataFacade.h | 19 ++------- Server/DataStructures/SharedDataType.h | 47 ++++++++++++---------- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index a18b93a28..5e80cfee3 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -173,10 +173,6 @@ private: sizeof(OriginalEdgeData) ); m_via_node_list[i] = current_edge_data.via_node; - // if(current_edge_data.via_node == 0 && current_edge_data.compressed_geometry) { - // SimpleLogger().Write() << "0 at index " << i; - // } - m_name_ID_list[i] = current_edge_data.name_id; m_turn_instruction_list[i] = current_edge_data.turn_instruction; m_egde_is_compressed[i] = current_edge_data.compressed_geometry; @@ -184,7 +180,6 @@ private: ++compressed; } } - // SimpleLogger().Write(logDEBUG) << "compressed: " << compressed; edges_input_stream.close(); } @@ -202,6 +197,7 @@ private: (char *)&number_of_indices, sizeof(unsigned) ); + m_geometry_indices.resize(number_of_indices); geometry_stream.read( (char *)&(m_geometry_indices[0]), @@ -250,8 +246,6 @@ 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], diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 5d7fe6310..5e90deee2 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -92,8 +92,6 @@ private: > > m_static_rtree; - // SharedDataFacade() { } - void LoadTimestamp() { char * timestamp_ptr = shared_memory + data_layout->GetTimeStampOffset(); m_timestamp.resize(data_layout->timestamp_length); @@ -130,7 +128,7 @@ private: ); GraphEdge * graph_edges_ptr = (GraphEdge *)( - shared_memory + data_layout->GetGraphEdgeListOffsett() + shared_memory + data_layout->GetGraphEdgeListOffset() ); typename ShM::vector node_list( @@ -210,16 +208,16 @@ private: void LoadGeometries() { unsigned * geometries_compressed_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometriesIndexListOffset() + shared_memory + data_layout->GetGeometriesIndicatorOffset() ); typename ShM::vector egde_is_compressed( geometries_compressed_ptr, - data_layout->geometries_index_list_size + data_layout->geometries_indicators ); m_egde_is_compressed.swap(egde_is_compressed); unsigned * geometries_index_ptr = (unsigned *)( - shared_memory + data_layout->GetGeometriesIndicatorOffset() + shared_memory + data_layout->GetGeometriesIndexListOffset() ); typename ShM::vector geometry_begin_indices( geometries_index_ptr, @@ -406,15 +404,6 @@ public: resulting_phantom_node, zoom_level ); - - if ( found ) { - resulting_phantom_node.name_id = GetNameIndexFromEdgeID( - FindEdge( - resulting_phantom_node.forward_node_id, - resulting_phantom_node.reverse_node_id - ) - ); - } return found; } diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index 388374bd7..e3565ad1c 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -58,7 +58,7 @@ struct SharedDataLayout { uint64_t r_search_tree_size; uint64_t geometries_index_list_size; uint64_t geometries_list_size; - uint64_t geometries_compression; + uint64_t geometries_indicators; unsigned checksum; unsigned timestamp_length; @@ -77,7 +77,7 @@ struct SharedDataLayout { r_search_tree_size(0), geometries_index_list_size(0), geometries_list_size(0), - geometries_compression(0), + geometries_indicators(0), checksum(0), timestamp_length(0) @@ -87,19 +87,34 @@ struct SharedDataLayout { void PrintInformation() const { SimpleLogger().Write(logDEBUG) << "-"; + SimpleLogger().Write(logDEBUG) << "GetSizeOfLayout: " << GetSizeOfLayout(); SimpleLogger().Write(logDEBUG) << "name_index_list_size: " << name_index_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetNameIndexOffset(); SimpleLogger().Write(logDEBUG) << "name_char_list_size: " << name_char_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetNameListOffset(); SimpleLogger().Write(logDEBUG) << "name_id_list_size: " << name_id_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetNameIDListOffset(); SimpleLogger().Write(logDEBUG) << "via_node_list_size: " << via_node_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetViaNodeListOffset(); SimpleLogger().Write(logDEBUG) << "graph_node_list_size: " << graph_node_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetGraphNodeListOffset(); SimpleLogger().Write(logDEBUG) << "graph_edge_list_size: " << graph_edge_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetGraphEdgeListOffset(); SimpleLogger().Write(logDEBUG) << "timestamp_length: " << timestamp_length; + SimpleLogger().Write(logDEBUG) << " " << GetTimeStampOffset(); SimpleLogger().Write(logDEBUG) << "coordinate_list_size: " << coordinate_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetCoordinateListOffset(); SimpleLogger().Write(logDEBUG) << "turn_instruction_list_size: " << turn_instruction_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetTurnInstructionListOffset(); SimpleLogger().Write(logDEBUG) << "r_search_tree_size: " << r_search_tree_size; - SimpleLogger().Write(logDEBUG) << "geometries_compression: " << geometries_compression << "/" << ((geometries_compression/32) + 1); + SimpleLogger().Write(logDEBUG) << " " << GetRSearchTreeOffset(); + SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << geometries_indicators << "/" << ((geometries_indicators/8) + 1); + SimpleLogger().Write(logDEBUG) << " " << GetGeometriesIndicatorOffset(); SimpleLogger().Write(logDEBUG) << "geometries_index_list_size: " << geometries_index_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetGeometriesIndexListOffset(); SimpleLogger().Write(logDEBUG) << "geometries_list_size: " << geometries_list_size; + SimpleLogger().Write(logDEBUG) << " " << GetGeometryListOffset(); + SimpleLogger().Write(logDEBUG) << "checksum offset: " << GetChecksumOffset(); SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); SimpleLogger().Write(logDEBUG) << "ram index file name: " << ram_index_file_name; } @@ -116,12 +131,11 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32 + 1) * sizeof(unsigned) + + (geometries_indicators/32 + 1) * sizeof(unsigned) + (geometries_index_list_size * sizeof(unsigned) ) + (geometries_list_size * sizeof(unsigned) ) + sizeof(checksum) + 1024*sizeof(char); - PrintInformation(); return result; } @@ -154,10 +168,10 @@ struct SharedDataLayout { (via_node_list_size * sizeof(NodeID) ); return result; } - uint64_t GetGraphEdgeListOffsett() const { + uint64_t GetGraphEdgeListOffset() const { uint64_t result = - (name_index_list_size * sizeof(unsigned) ) + - (name_char_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)) ; @@ -171,7 +185,6 @@ struct SharedDataLayout { (via_node_list_size * sizeof(NodeID) ) + (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)); - SimpleLogger().Write(logDEBUG) << "GetTimeStampOffset: " << result; return result; } uint64_t GetCoordinateListOffset() const { @@ -183,7 +196,6 @@ struct SharedDataLayout { (graph_node_list_size * sizeof(QueryGraph::_StrNode)) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + (timestamp_length * sizeof(char) ); - SimpleLogger().Write(logDEBUG) << "GetCoordinateListOffset: " << result; return result; } uint64_t GetTurnInstructionListOffset() const { @@ -196,7 +208,6 @@ struct SharedDataLayout { (graph_edge_list_size * sizeof(QueryGraph::_StrEdge)) + (timestamp_length * sizeof(char) ) + (coordinate_list_size * sizeof(FixedPointCoordinate)); - SimpleLogger().Write(logDEBUG) << "GetTurnInstructionListOffset: " << result; return result; } uint64_t GetRSearchTreeOffset() const { @@ -210,7 +221,6 @@ struct SharedDataLayout { (timestamp_length * sizeof(char) ) + (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)); - SimpleLogger().Write(logDEBUG) << "GetRSearchTreeOffset: " << result; return result; } uint64_t GetGeometriesIndicatorOffset() const { @@ -225,13 +235,11 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ); - SimpleLogger().Write(logDEBUG) << "GetGeometriesIndicatorOffset: " << result; return result; } uint64_t GetGeometriesIndexListOffset() const - { - uint64_t result = + { uint64_t result = (name_index_list_size * sizeof(unsigned) ) + (name_char_list_size * sizeof(char) ) + (name_id_list_size * sizeof(unsigned) ) + @@ -242,8 +250,7 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32 + 1) * sizeof(unsigned); - SimpleLogger().Write(logDEBUG) << "GetGeometriesCompressedOffset: " << result; + (geometries_indicators/32 + 1) * sizeof(unsigned); return result; } @@ -259,9 +266,8 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32 + 1) * sizeof(unsigned) + + (geometries_indicators/32 + 1) * sizeof(unsigned) + (geometries_index_list_size * sizeof(unsigned) ); - SimpleLogger().Write(logDEBUG) << "GetGeometryListOffset: " << result; return result; } uint64_t GetChecksumOffset() const { @@ -276,10 +282,9 @@ struct SharedDataLayout { (coordinate_list_size * sizeof(FixedPointCoordinate) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) + (r_search_tree_size * sizeof(RTreeNode) ) + - (geometries_compression/32 + 1) * sizeof(unsigned) + + (geometries_indicators/32 + 1) * sizeof(unsigned) + (geometries_index_list_size * sizeof(unsigned) ) + (geometries_list_size * sizeof(unsigned) ); - SimpleLogger().Write(logDEBUG) << "GetChecksumOffset: " << result; return result; } }; From c6a58ff1b474e91e5116f753e3f1bae78aba697e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:28:57 +0200 Subject: [PATCH 77/89] remove debug lint again --- Server/DataStructures/SharedDataFacade.h | 2 -- Server/DataStructures/SharedDataType.h | 17 +---------------- datastore.cpp | 1 - 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/Server/DataStructures/SharedDataFacade.h b/Server/DataStructures/SharedDataFacade.h index 5e90deee2..21f2cb99a 100644 --- a/Server/DataStructures/SharedDataFacade.h +++ b/Server/DataStructures/SharedDataFacade.h @@ -142,7 +142,6 @@ private: m_query_graph.reset( new QueryGraph(node_list, edge_list) ); - } void LoadNodeAndEdgeInformation() { @@ -296,7 +295,6 @@ public: } } - //search graph access unsigned GetNumberOfNodes() const { return m_query_graph->GetNumberOfNodes(); diff --git a/Server/DataStructures/SharedDataType.h b/Server/DataStructures/SharedDataType.h index e3565ad1c..5efb19f3b 100644 --- a/Server/DataStructures/SharedDataType.h +++ b/Server/DataStructures/SharedDataType.h @@ -87,34 +87,19 @@ struct SharedDataLayout { void PrintInformation() const { SimpleLogger().Write(logDEBUG) << "-"; - SimpleLogger().Write(logDEBUG) << "GetSizeOfLayout: " << GetSizeOfLayout(); SimpleLogger().Write(logDEBUG) << "name_index_list_size: " << name_index_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetNameIndexOffset(); SimpleLogger().Write(logDEBUG) << "name_char_list_size: " << name_char_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetNameListOffset(); SimpleLogger().Write(logDEBUG) << "name_id_list_size: " << name_id_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetNameIDListOffset(); SimpleLogger().Write(logDEBUG) << "via_node_list_size: " << via_node_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetViaNodeListOffset(); SimpleLogger().Write(logDEBUG) << "graph_node_list_size: " << graph_node_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetGraphNodeListOffset(); SimpleLogger().Write(logDEBUG) << "graph_edge_list_size: " << graph_edge_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetGraphEdgeListOffset(); SimpleLogger().Write(logDEBUG) << "timestamp_length: " << timestamp_length; - SimpleLogger().Write(logDEBUG) << " " << GetTimeStampOffset(); SimpleLogger().Write(logDEBUG) << "coordinate_list_size: " << coordinate_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetCoordinateListOffset(); SimpleLogger().Write(logDEBUG) << "turn_instruction_list_size: " << turn_instruction_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetTurnInstructionListOffset(); SimpleLogger().Write(logDEBUG) << "r_search_tree_size: " << r_search_tree_size; - SimpleLogger().Write(logDEBUG) << " " << GetRSearchTreeOffset(); - SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << geometries_indicators << "/" << ((geometries_indicators/8) + 1); - SimpleLogger().Write(logDEBUG) << " " << GetGeometriesIndicatorOffset(); + SimpleLogger().Write(logDEBUG) << "geometries_indicators: " << geometries_indicators << "/" << ((geometries_indicators/8) + 1); SimpleLogger().Write(logDEBUG) << "geometries_index_list_size: " << geometries_index_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetGeometriesIndexListOffset(); SimpleLogger().Write(logDEBUG) << "geometries_list_size: " << geometries_list_size; - SimpleLogger().Write(logDEBUG) << " " << GetGeometryListOffset(); - SimpleLogger().Write(logDEBUG) << "checksum offset: " << GetChecksumOffset(); SimpleLogger().Write(logDEBUG) << "sizeof(checksum): " << sizeof(checksum); SimpleLogger().Write(logDEBUG) << "ram index file name: " << ram_index_file_name; } diff --git a/datastore.cpp b/datastore.cpp index 0b836c3c5..691606a76 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -341,7 +341,6 @@ int main( const int argc, const char * argv[] ) { OriginalEdgeData current_edge_data; 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) From 0f8a32f38cdb5beb799d9fa0cbe91638f90e75c5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 16:42:55 +0200 Subject: [PATCH 78/89] shape up code --- Contractor/EdgeBasedGraphFactory.cpp | 2 -- DataStructures/SharedMemoryVectorWrapper.h | 14 +++----------- Server/DataStructures/InternalDataFacade.h | 2 -- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index b067e6b2f..6a01b19c2 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -471,7 +471,6 @@ void EdgeBasedGraphFactory::Run( const unsigned original_number_of_nodes = m_node_based_graph->GetNumberOfNodes(); const unsigned original_number_of_edges = m_node_based_graph->GetNumberOfEdges(); - SimpleLogger().Write(logDEBUG) << "Input graph has " << original_number_of_nodes << " nodes and " << original_number_of_edges << " edges"; Percent p(original_number_of_nodes); unsigned removed_node_count = 0; @@ -850,7 +849,6 @@ void EdgeBasedGraphFactory::Run( edge_data_file.write( (char*)&original_edges_counter, sizeof(unsigned) ); edge_data_file.close(); - SimpleLogger().Write(logDEBUG) << "serializing geometry to " << geometry_filename; m_geometry_compressor.SerializeInternalVector( geometry_filename ); SimpleLogger().Write() << "Generated " << m_edge_based_node_list.size() << " edge based nodes"; diff --git a/DataStructures/SharedMemoryVectorWrapper.h b/DataStructures/SharedMemoryVectorWrapper.h index 8049abae5..b0e85dfbc 100644 --- a/DataStructures/SharedMemoryVectorWrapper.h +++ b/DataStructures/SharedMemoryVectorWrapper.h @@ -82,9 +82,7 @@ public: SharedMemoryWrapper(DataT * ptr, std::size_t size) : m_ptr(ptr), m_size(size) - { - SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << size; - } + { } void swap( SharedMemoryWrapper & other ) { BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid"); @@ -140,16 +138,12 @@ public: SharedMemoryWrapper() : m_ptr(NULL), m_size(0) - { - SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << m_size; - } + { } SharedMemoryWrapper(unsigned * ptr, std::size_t size) : m_ptr(ptr), m_size(size) - { - SimpleLogger().Write(logDEBUG) << "generated std::vector of size " << m_size; - } + { } void swap( SharedMemoryWrapper & other ) { BOOST_ASSERT_MSG(m_size != 0 || other.size() != 0, "size invalid"); @@ -191,7 +185,6 @@ public: } }; - template struct ShM { typedef typename boost::conditional< @@ -201,5 +194,4 @@ struct ShM { >::type vector; }; - #endif //SHARED_MEMORY_VECTOR_WRAPPER_H diff --git a/Server/DataStructures/InternalDataFacade.h b/Server/DataStructures/InternalDataFacade.h index 5e80cfee3..e82ae356d 100644 --- a/Server/DataStructures/InternalDataFacade.h +++ b/Server/DataStructures/InternalDataFacade.h @@ -133,7 +133,6 @@ private: std::ios::binary ); - SimpleLogger().Write(logDEBUG) << "Loading node data"; NodeInfo current_node; unsigned number_of_coordinates = 0; nodes_input_stream.read( @@ -152,7 +151,6 @@ private: } nodes_input_stream.close(); - SimpleLogger().Write(logDEBUG) << "Loading edge data"; boost::filesystem::ifstream edges_input_stream( edges_file, std::ios::binary From ef7619d66411a7deb0a27df177372218cea91e05 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Tue, 22 Apr 2014 17:44:16 +0200 Subject: [PATCH 79/89] fix signed/unsigned comparison --- Contractor/GeometryCompressor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Contractor/GeometryCompressor.cpp b/Contractor/GeometryCompressor.cpp index 53cca3fdf..e0d5752d0 100644 --- a/Contractor/GeometryCompressor.cpp +++ b/Contractor/GeometryCompressor.cpp @@ -123,8 +123,8 @@ void GeometryCompressor::CompressEdge(const EdgeID edge_id_1, BOOST_ASSERT(SPECIAL_EDGEID != edge_id_2); BOOST_ASSERT(SPECIAL_NODEID != via_node_id); BOOST_ASSERT(SPECIAL_NODEID != target_node_id); - BOOST_ASSERT(std::numeric_limits::max() != weight1); - BOOST_ASSERT(std::numeric_limits::max() != weight2); + BOOST_ASSERT(std::numeric_limits::max() != weight1); + BOOST_ASSERT(std::numeric_limits::max() != weight2); // append list of removed edge_id plus via node to surviving edge id: // Date: Wed, 23 Apr 2014 17:03:26 +0200 Subject: [PATCH 80/89] fix and/or remove unused variables --- Contractor/EdgeBasedGraphFactory.cpp | 4 +++- DataStructures/InputReaderFactory.h | 10 ++++++---- Descriptors/JSONDescriptor.h | 13 ------------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 6a01b19c2..82e10b254 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -290,10 +290,12 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( BOOST_ASSERT( v != SPECIAL_NODEID ); BOOST_ASSERT( e1 != SPECIAL_EDGEID ); +#ifndef NDEBUG // find forward edge id and const EdgeID e1b = m_node_based_graph->FindEdge(u, v); BOOST_ASSERT( e1 == e1b ); - +#endif + BOOST_ASSERT( e1 != SPECIAL_EDGEID ); const EdgeData & forward_data = m_node_based_graph->GetEdgeData(e1); diff --git a/DataStructures/InputReaderFactory.h b/DataStructures/InputReaderFactory.h index 26418c1f2..3ca09fe03 100644 --- a/DataStructures/InputReaderFactory.h +++ b/DataStructures/InputReaderFactory.h @@ -29,6 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INPUTREADERFACTORY_H #define INPUTREADERFACTORY_H +#include + #include #include @@ -51,21 +53,21 @@ int readFromBz2Stream( void* pointer, char* buffer, int len ) { return read; } else if(BZ_STREAM_END == context->error) { BZ2_bzReadGetUnused(&context->error, context->bz2, &unusedTmpVoid, &context->nUnused); - if(BZ_OK != context->error) {std::cerr << "Could not BZ2_bzReadGetUnused" <error, "Could not BZ2_bzReadGetUnused"); unusedTmp = (char*)unusedTmpVoid; for(int i=0;inUnused;i++) { context->unused[i] = unusedTmp[i]; } BZ2_bzReadClose(&context->error, context->bz2); - if(BZ_OK != context->error) {std::cerr << "Could not BZ2_bzReadClose" <error, "Could not BZ2_bzReadClose"); context->error = BZ_STREAM_END; // set to the stream end for next call to this function if(0 == context->nUnused && feof(context->file)) { return read; } else { context->bz2 = BZ2_bzReadOpen(&context->error, context->file, 0, 0, context->unused, context->nUnused); - if(NULL == context->bz2){std::cerr << "Could not open file" <bz2, "Could not open file"); } - } else { std::cerr << "Could not read bz2 file" << std::endl; exit(-1); } + } else { BOOST_ASSERT_MSG(false, "Could not read bz2 file"); } } return read; } diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 9b6985b4f..d5e60a52e 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -131,12 +131,6 @@ public: //check if first segment is non-zero std::string road_name; - int source_duration = phantom_nodes.source_phantom.GetForwardWeightPlusOffset(); - if (!raw_route.source_traversed_in_reverse) - { - source_duration = phantom_nodes.source_phantom.GetReverseWeightPlusOffset(); - } - BOOST_ASSERT(source_duration >= 0); road_name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); // for each unpacked segment add the leg to the description @@ -156,13 +150,6 @@ public: //check if last segment is non-zero road_name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id); - int target_duration = phantom_nodes.target_phantom.GetForwardWeightPlusOffset(); - if (raw_route.target_traversed_in_reverse) - { - target_duration = phantom_nodes.target_phantom.GetReverseWeightPlusOffset(); - } - BOOST_ASSERT(target_duration >= 0); - description_factory.SetStartSegment(phantom_nodes.source_phantom, raw_route.source_traversed_in_reverse); reply.content.push_back("0," "\"status_message\": \"Found route between points\","); From 0eed39cdf1adf478aeb368251395ba8d3a7b1d84 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 24 Apr 2014 18:13:50 +0200 Subject: [PATCH 81/89] rebase branch onto develop --- Contractor/Contractor.h | 1 - Contractor/EdgeBasedGraphFactory.cpp | 18 ++-- DataStructures/EdgeBasedNode.h | 139 ++++++--------------------- Descriptors/JSONDescriptor.h | 4 +- features/options/routed/help.feature | 8 +- prepare.cpp | 5 +- profiles/bicycle.lua | 30 +----- routed.cpp | 2 +- 8 files changed, 51 insertions(+), 156 deletions(-) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 64e2eac37..55d54c83b 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -126,7 +126,6 @@ public: newEdge.source = diter->source(); newEdge.target = diter->target(); newEdge.data = ContractorEdgeData( (std::max)((int)diter->weight(), 1 ), 1, diter->id(), false, diter->isForward(), diter->isBackward()); - BOOST_ASSERT_MSG( newEdge.data.distance > 0, "edge distance < 1" ); #ifndef NDEBUG if ( newEdge.data.distance > 24 * 60 * 60 * 10 ) { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 82e10b254..f312fd68e 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -43,15 +43,15 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( std::vector & barrier_node_list, std::vector & traffic_light_node_list, std::vector & input_restrictions_list, - std::vector & node_info_list, - SpeedProfileProperties speed_profile + std::vector & m_node_info_list, + SpeedProfileProperties & speed_profile ) : speed_profile(speed_profile), m_turn_restrictions_count(0), m_number_of_edge_based_nodes(std::numeric_limits::max()), - m_node_info_list(node_info_list), + m_node_info_list(m_node_info_list), max_id(0) { - BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { + BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { std::pair restriction_source = std::make_pair(restriction.fromNode, restriction.viaNode); unsigned index; @@ -78,7 +78,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( ); } - m_barrier_nodes.insert( + m_barrier_nodes.insert( barrier_node_list.begin(), barrier_node_list.end() ); @@ -109,7 +109,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( } if( edge.source == edge.target ) { - continue; + continue; } edge.data.distance = (std::max)((int)import_edge.weight(), 1 ); @@ -295,7 +295,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode( const EdgeID e1b = m_node_based_graph->FindEdge(u, v); BOOST_ASSERT( e1 == e1b ); #endif - + BOOST_ASSERT( e1 != SPECIAL_EDGEID ); const EdgeData & forward_data = m_node_based_graph->GetEdgeData(e1); @@ -906,10 +906,10 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn( const EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2); if(!data1.contraFlow && data2.contraFlow) { - return TurnInstructionsClass::EnterAgainstAllowedDirection; + return TurnInstructionsClass::EnterAgainstAllowedDirection; } if(data1.contraFlow && !data2.contraFlow) { - return TurnInstructionsClass::LeaveAgainstAllowedDirection; + return TurnInstructionsClass::LeaveAgainstAllowedDirection; } //roundabouts need to be handled explicitely diff --git a/DataStructures/EdgeBasedNode.h b/DataStructures/EdgeBasedNode.h index 7a314369b..d76a4958b 100644 --- a/DataStructures/EdgeBasedNode.h +++ b/DataStructures/EdgeBasedNode.h @@ -2,11 +2,12 @@ #define EDGE_BASED_NODE_H #include "../Util/MercatorUtil.h" +#include "../Util/SimpleLogger.h" #include "../typedefs.h" #include -// An EdgeBasedNode represents a node in the edge-expanded graph. +#include #include @@ -63,15 +64,13 @@ struct EdgeBasedNode { inline static double ComputePerpendicularDistance( const FixedPointCoordinate & coord_a, const FixedPointCoordinate & coord_b, - // the query location on the line defined by p and q. - double ComputePerpendicularDistance( const FixedPointCoordinate & query_location, FixedPointCoordinate & nearest_location, double & r ) { BOOST_ASSERT( query_location.isValid() ); - const double epsilon = 1.0/precision; + const double x = lat2y(query_location.lat/COORDINATE_PRECISION); const double y = query_location.lon/COORDINATE_PRECISION; const double a = lat2y(coord_a.lat/COORDINATE_PRECISION); const double b = coord_a.lon/COORDINATE_PRECISION; @@ -94,14 +93,18 @@ struct EdgeBasedNode { nY = 0.; } - // p, q : the end points of the underlying edge + r = (p - nY*a)/c;// These values are actually n/m+n and m/m+n , we need + // not calculate the explicit values of m an n as we + // are just interested in the ratio if( std::isnan(r) ) { r = ((coord_b.lat == query_location.lat) && (coord_b.lon == query_location.lon)) ? 1. : 0.; - - // r : query location - const Point r(lat2y(query_location.lat/COORDINATE_PRECISION), + } else if( std::abs(r) <= std::numeric_limits::epsilon() ) { + r = 0.; } else if( std::abs(r-1.) <= std::numeric_limits::epsilon() ) { - query_location.lon/COORDINATE_PRECISION); + r = 1.; + } + BOOST_ASSERT( !std::isnan(r) ); + if( r <= 0. ){ nearest_location.lat = coord_a.lat; nearest_location.lon = coord_a.lon; } else if( r >= 1. ){ @@ -110,18 +113,17 @@ struct EdgeBasedNode { } else { // point lies in between nearest_location.lat = y2lat(p)*COORDINATE_PRECISION; - nearest_location = ComputeNearestPointOnSegment(foot, ratio); - + nearest_location.lon = q*COORDINATE_PRECISION; + } BOOST_ASSERT( nearest_location.isValid() ); // TODO: Replace with euclidean approximation when k-NN search is done // const double approximated_distance = FixedPointCoordinate::ApproximateEuclideanDistance( - const double approximated_distance = FixedPointCoordinate::ApproximateDistance(query_location, nearest_location); - + const double approximated_distance = FixedPointCoordinate::ApproximateDistance( query_location, nearest_location ); - BOOST_ASSERT( 0.0 <= approximated_distance ); + BOOST_ASSERT( 0. <= approximated_distance ); return approximated_distance; } @@ -129,7 +131,7 @@ struct EdgeBasedNode { const FixedPointCoordinate & a, const FixedPointCoordinate & b ) { - return other.id < id; + FixedPointCoordinate centroid; //The coordinates of the midpoint are given by: //x = (x1 + x2) /2 and y = (y1 + y2) /2. centroid.lon = (std::min(a.lon, b.lon) + std::max(a.lon, b.lon))/2; @@ -141,103 +143,18 @@ struct EdgeBasedNode { return packed_geometry_id != SPECIAL_EDGEID; } - // Returns the midpoint of the underlying edge. - inline FixedPointCoordinate Centroid() const { - return FixedPointCoordinate((lat1+lat2)/2, (lon1+lon2)/2); - } - - NodeID forward_edge_based_node_id; + NodeID forward_edge_based_node_id; // needed for edge-expanded graph NodeID reverse_edge_based_node_id; // needed for edge-expanded graph - NodeID u; - NodeID v; - unsigned name_id; - int forward_weight; - int reverse_weight; - int forward_offset; - int reverse_offset; - unsigned short fwd_segment_position; - unsigned short rev_segment_position:14; //TODO: not actually needed! - bool belongsToTinyComponent:1; - NodeID name_id; - - // The weight of the underlying edge. - unsigned weight:31; - - int reverse_weight; - -private: - - typedef std::pair Point; - - // Compute the perpendicular foot of point r on the line defined by p and q. - Point ComputePerpendicularFoot(const Point &p, const Point &q, const Point &r, double epsilon) const { - - // the projection of r onto the line pq - double foot_x, foot_y; - - const bool is_parallel_to_y_axis = std::abs(q.first - p.first) < epsilon; - - if( is_parallel_to_y_axis ) { - foot_x = q.first; - foot_y = r.second; - } else { - // the slope of the line through (a|b) and (c|d) - const double m = (q.second - p.second) / (q.first - p.first); - - // Projection of (x|y) onto the line joining (a|b) and (c|d). - foot_x = ((r.first + (m*r.second)) + (m*m*p.first - m*p.second))/(1.0 + m*m); - foot_y = p.second + m*(foot_x - p.first); - } - - return Point(foot_x, foot_y); - } - - // Compute the ratio of the line segment pr to line segment pq. - double ComputeRatio(const Point & p, const Point & q, const Point & r, double epsilon) const { - - const bool is_parallel_to_x_axis = std::abs(q.second-p.second) < epsilon; - const bool is_parallel_to_y_axis = std::abs(q.first -p.first ) < epsilon; - - double ratio; - - if( !is_parallel_to_y_axis ) { - ratio = (r.first - p.first)/(q.first - p.first); - } else if( !is_parallel_to_x_axis ) { - ratio = (r.second - p.second)/(q.second - p.second); - } else { - // (a|b) and (c|d) are essentially the same point - // by convention, we set the ratio to 0 in this case - //ratio = ((lat2 == query_location.lat) && (lon2 == query_location.lon)) ? 1. : 0.; - ratio = 0.0; - } - - // Round to integer if the ratio is close to 0 or 1. - if( std::abs(ratio) <= epsilon ) { - ratio = 0.0; - } else if( std::abs(ratio-1.0) <= epsilon ) { - ratio = 1.0; - } - - return ratio; - } - - // Computes the point on the segment pq which is nearest to a point r = p + lambda * (q-p). - // p and q are the end points of the underlying edge. - FixedPointCoordinate ComputeNearestPointOnSegment(const Point & r, double lambda) const { - - if( lambda <= 0.0 ) { - return FixedPointCoordinate(lat1, lon1); - } else if( lambda >= 1.0 ) { - return FixedPointCoordinate(lat2, lon2); - } - - // r lies between p and q - return FixedPointCoordinate( - y2lat(r.first)*COORDINATE_PRECISION, - r.second*COORDINATE_PRECISION - ); - } - + NodeID u; // indices into the coordinates array + NodeID v; // indices into the coordinates array + unsigned name_id; // id of the edge name + int forward_weight; // weight of the edge + int reverse_weight; // weight in the other direction (may be different) + int forward_offset; // prefix sum of the weight up the edge TODO: short must suffice + int reverse_offset; // prefix sum of the weight from the edge TODO: short must suffice + unsigned packed_geometry_id; // if set, then the edge represents a packed geometry + unsigned short fwd_segment_position; // segment id in a compressed geometry + bool belongsToTinyComponent; }; #endif //EDGE_BASED_NODE_H diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index d5e60a52e..c54632cf4 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -91,7 +91,7 @@ public: void SetConfig(const DescriptorConfig & c) { config = c; } int DescribeLeg( - const std::vector & route_leg, + const std::vector route_leg, const PhantomNodes & leg_phantoms ) { int added_element_count = 0; @@ -451,7 +451,7 @@ public: //Fetch data from Factory and generate a string from it. BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) { - TurnInstruction current_instruction = segment.turn_instruction & TurnInstructionsClass::InverseAccessRestrictionFlag; + TurnInstruction current_instruction = segment.turn_instruction & TurnInstructionsClass::InverseAccessRestrictionFlag; entered_restricted_area_count += (current_instruction != segment.turn_instruction); if (TurnInstructionsClass::TurnIsNecessary( current_instruction) ) { diff --git a/features/options/routed/help.feature b/features/options/routed/help.feature index 3feb95746..9603c40dd 100644 --- a/features/options/routed/help.feature +++ b/features/options/routed/help.feature @@ -25,7 +25,7 @@ Feature: osrm-routed command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" - And stdout should contain 21 lines + And stdout should contain 22 lines And it should exit with code 0 Scenario: osrm-routed - Help, short @@ -49,7 +49,7 @@ Feature: osrm-routed command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" - And stdout should contain 21 lines + And stdout should contain 22 lines And it should exit with code 0 Scenario: osrm-routed - Help, long @@ -73,5 +73,5 @@ Feature: osrm-routed command line options: help And stdout should contain "--port" And stdout should contain "--threads" And stdout should contain "--sharedmemory" - And stdout should contain 21 lines - And it should exit with code 0 \ No newline at end of file + And stdout should contain 22 lines + And it should exit with code 0 diff --git a/prepare.cpp b/prepare.cpp index 631e61efb..3b1ca3155 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -341,6 +341,9 @@ int main (int argc, char *argv[]) { max_used_node_id = std::max(max_used_node_id, edge.source); max_used_node_id = std::max(max_used_node_id, edge.target); + + SimpleLogger().Write(logDEBUG) << "generated edge (" << edge.source << ", " << edge.target << ")=" << edge.data.distance; + } SimpleLogger().Write(logDEBUG) << "input graph has " << edgeBasedNodeNumber << " nodes"; SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes"; @@ -435,7 +438,7 @@ int main (int argc, char *argv[]) { return 1; } catch ( const std::exception &e ) { SimpleLogger().Write(logWARNING) << "Exception occured: " << e.what() << std::endl; - return -1; + return 1; } return 0; } diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index b935bafbc..3efa3d025 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -146,29 +146,6 @@ function node_function (node) -- return 1 end - -- flag node if it carries a traffic light - if traffic_signal == "traffic_signals" then - node.traffic_light = true - end - - -- parse access and barrier tags - if access and access ~= "" then - if access_tag_blacklist[access] then - node.bollard = true - else - node.bollard = false - end - elseif barrier and barrier ~= "" then - if barrier_whitelist[barrier] then - node.bollard = false - else - node.bollard = true - end - end - - return 1 -end - function way_function (way) -- initial routability check, filters out buildings, boundaries, etc local highway = way.tags:Find("highway") @@ -202,9 +179,9 @@ function way_function (way) local name = way.tags:Find("name") local ref = way.tags:Find("ref") local junction = way.tags:Find("junction") - local maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") ) - local maxspeed_forward = parseMaxspeed(way.tags:Find( "maxspeed:forward")) - local maxspeed_backward = parseMaxspeed(way.tags:Find( "maxspeed:backward")) + local maxspeed = parse_maxspeed(way.tags:Find ( "maxspeed") ) + local maxspeed_forward = parse_maxspeed(way.tags:Find( "maxspeed:forward")) + local maxspeed_backward = parse_maxspeed(way.tags:Find( "maxspeed:backward")) local barrier = way.tags:Find("barrier") local oneway = way.tags:Find("oneway") local onewayClass = way.tags:Find("oneway:bicycle") @@ -343,7 +320,6 @@ function way_function (way) end end - -- cycleways if cycleway and cycleway_tags[cycleway] then way.speed = bicycle_speeds["cycleway"] diff --git a/routed.cpp b/routed.cpp index 6b53ee740..855ec04c4 100644 --- a/routed.cpp +++ b/routed.cpp @@ -108,7 +108,7 @@ int main (int argc, const char * argv[]) SimpleLogger().Write() << "HSGR file:\t" << server_paths["hsgrdata"]; SimpleLogger().Write(logDEBUG) << "Nodes file:\t" << server_paths["nodesdata"]; SimpleLogger().Write(logDEBUG) << "Edges file:\t" << server_paths["edgesdata"]; - SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"]; + SimpleLogger().Write(logDEBUG) << "Geometry file:\t" << server_paths["geometries"]; SimpleLogger().Write(logDEBUG) << "RAM file:\t" << server_paths["ramindex"]; SimpleLogger().Write(logDEBUG) << "Index file:\t" << server_paths["fileindex"]; SimpleLogger().Write(logDEBUG) << "Names file:\t" << server_paths["namesdata"]; From b0b67a0cdc8fba3cd75f12ded875a0b91c376a15 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 24 Apr 2014 18:14:35 +0200 Subject: [PATCH 82/89] fix typo setting potentially wrong flags in debug build --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 021cbfe28..155201183 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug) message(STATUS "Configuring OSRM in debug mode") if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") message(STATUS "adding profiling flags") - set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline") set(CMAKE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -fno-inline") endif() endif() From 2ec952032ae6af9b7fa9031ebe7df68c313ec1e2 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 13:22:58 +0200 Subject: [PATCH 83/89] fix rounding of travel times --- Descriptors/DescriptionFactory.h | 2 +- Descriptors/JSONDescriptor.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Descriptors/DescriptionFactory.h b/Descriptors/DescriptionFactory.h index ed22a11cb..11eb28220 100644 --- a/Descriptors/DescriptionFactory.h +++ b/Descriptors/DescriptionFactory.h @@ -71,7 +71,7 @@ public: ) { //compute distance/duration for route summary intToString(round(distance), lengthString); - int travel_time = time/10; + int travel_time = round(time/10.); intToString(std::max(travel_time, 1), durationString); } } summary; diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index c54632cf4..7b0522017 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -129,6 +129,8 @@ public: return; } + SimpleLogger().Write(logDEBUG) << "distance: " << raw_route.lengthOfShortestPath; + //check if first segment is non-zero std::string road_name; road_name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id); @@ -488,7 +490,7 @@ public: intToString(necessary_segments_running_index, temp_length); reply.content.push_back(temp_length); reply.content.push_back(","); - intToString(segment.duration/10, temp_duration); + intToString(round(segment.duration/10.), temp_duration); reply.content.push_back(temp_duration); reply.content.push_back(",\""); intToString(segment.length, temp_length); From ca6515c58a3519e3edcdbc029144c421e7f50e0e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 13:23:27 +0200 Subject: [PATCH 84/89] fix tests to reflect proper rounding of travel times --- features/car/maxspeed.feature | 10 +++++----- features/car/speed.feature | 12 ++++++------ features/step_definitions/routability.rb | 8 ++++---- features/testbot/opposite.feature | 2 +- features/testbot/speed.feature | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/features/car/maxspeed.feature b/features/car/maxspeed.feature index df37e3fb5..f3771cc2b 100644 --- a/features/car/maxspeed.feature +++ b/features/car/maxspeed.feature @@ -18,7 +18,7 @@ When a max speed is set, osrm will use 2/3 of that as the actual speed. When I route I should get | from | to | route | speed | | a | b | ab | 85 km/h | - | b | c | bc | 40 km/h | + | b | c | bc | 39 km/h | Scenario: Car - Do not ignore maxspeed when higher than way speed Given the node map @@ -32,7 +32,7 @@ When a max speed is set, osrm will use 2/3 of that as the actual speed. When I route I should get | from | to | route | speed | | a | b | ab | 25 km/h | - | b | c | bc | 60 km/h | + | b | c | bc | 59 km/h | Scenario: Car - Forward/backward maxspeed Given a grid size of 100 meters @@ -43,8 +43,8 @@ When a max speed is set, osrm will use 2/3 of that as the actual speed. | primary | 60 | | | 40 km/h | 40 km/h | | primary | | 60 | | 40 km/h | 65 km/h | | primary | | | 60 | 65 km/h | 40 km/h | - | primary | 15 | 60 | | 40 km/h | 10 km/h | - | primary | 15 | | 60 | 10 km/h | 40 km/h | + | primary | 15 | 60 | | 40 km/h | 9 km/h | + | primary | 15 | | 60 | 9 km/h | 40 km/h | | primary | 15 | 30 | 60 | 20 km/h | 40 km/h | Scenario: Car - Maxspeed should not allow routing on unroutable ways @@ -62,4 +62,4 @@ When a max speed is set, osrm will use 2/3 of that as the actual speed. | runway | | | | | | | | runway | | | 100 | | | | | runway | | | | 100 | | | - | runway | | | | | 100 | | \ No newline at end of file + | runway | | | | | 100 | | diff --git a/features/car/speed.feature b/features/car/speed.feature index 261f9aa62..a7a614a19 100644 --- a/features/car/speed.feature +++ b/features/car/speed.feature @@ -1,20 +1,20 @@ -@routing @car @speed +@routing @car @speed Feature: Car - speeds Background: Given the profile "car" And a grid size of 1000 meters - + Scenario: Car - speed of various way types Then routability should be | highway | oneway | bothw | | motorway | no | 90 km/h | | motorway_link | no | 75 km/h | - | trunk | no | 85 km/h | - | trunk_link | no | 70 km/h | - | primary | no | 65 km/h | + | trunk | no | 84 km/h | + | trunk_link | no | 69 km/h | + | primary | no | 64 km/h | | primary_link | no | 60 km/h | - | secondary | no | 55 km/h | + | secondary | no | 54 km/h | | secondary_link | no | 50 km/h | | tertiary | no | 40 km/h | | tertiary_link | no | 30 km/h | diff --git a/features/step_definitions/routability.rb b/features/step_definitions/routability.rb index d8a8a3945..cea5481ba 100644 --- a/features/step_definitions/routability.rb +++ b/features/step_definitions/routability.rb @@ -11,7 +11,7 @@ def test_routability_row i r[:status] = route_status r[:response] if r[:status].empty? == false r[:route] = way_list r[:json]['route_instructions'] - + if r[:route]=="w#{i}" r[:time] = r[:json]['route_summary']['total_time'] r[:distance] = r[:json]['route_summary']['total_distance'] @@ -24,7 +24,7 @@ def test_routability_row i end result[direction] = r end - + # check if forw and backw returned the same values result['bothw'] = {} [:status,:time,:distance,:speed].each do |key| @@ -62,12 +62,12 @@ Then /^routability should be$/ do |table| else raise "*** Unknown expectation format: #{want}" end - + if FuzzyMatch.match output_row[direction], want output_row[direction] = row[direction] end end - + if output_row != row log_fail row,output_row,result end diff --git a/features/testbot/opposite.feature b/features/testbot/opposite.feature index cd350e73b..9fdce5675 100644 --- a/features/testbot/opposite.feature +++ b/features/testbot/opposite.feature @@ -15,4 +15,4 @@ Feature: Separate settings for forward/backward direction When I route I should get | from | to | route | distance | speed | | a | d | abcd | 300 +- 1m | 36 km/h | - | d | a | abcd | 300 +- 1m | 16 km/h | + | d | a | abcd | 300 +- 1m | 15 km/h | diff --git a/features/testbot/speed.feature b/features/testbot/speed.feature index c9a983136..81674e944 100644 --- a/features/testbot/speed.feature +++ b/features/testbot/speed.feature @@ -28,4 +28,4 @@ Feature: Testbot - speeds When I route I should get | from | to | route | speed | time | distance | | a | b | ab | 36 km/h | 10s | 100m | - | b | a | ab | 16 km/h | 22s | 100m | + | b | a | ab | 15 km/h | 23s | 100m | From 16ca8da4382d538bce70085f624e3bd736c0da1e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 13:31:08 +0200 Subject: [PATCH 85/89] remove deactivated debug out for good --- DataStructures/PhantomNodes.h | 30 ---------------------- Descriptors/DescriptionFactory.cpp | 20 --------------- RoutingAlgorithms/AlternativePathRouting.h | 30 ---------------------- 3 files changed, 80 deletions(-) diff --git a/DataStructures/PhantomNodes.h b/DataStructures/PhantomNodes.h index 04380d53a..c7b8517c4 100644 --- a/DataStructures/PhantomNodes.h +++ b/DataStructures/PhantomNodes.h @@ -63,9 +63,7 @@ struct PhantomNode { return 0; } - // SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight; const int result = (forward_offset + forward_weight); - // SimpleLogger().Write(logDEBUG) << "forward queue weight: " << result; return result; } @@ -75,9 +73,7 @@ struct PhantomNode { return 0; } - // SimpleLogger().Write(logDEBUG) << "->rev_offset: " << reverse_offset << ", weight: " << reverse_weight; const int result = (reverse_offset + reverse_weight); - // SimpleLogger().Write(logDEBUG) << "reverse queue weight: " << result; return result; } @@ -151,32 +147,6 @@ struct PhantomNodes { return source_phantom == target_phantom; } - - // bool ComputeForwardQueueOffset() const - // { - // if (source_phantom.forward_node_id == target_phantom.forward_node_id) - // { - // const int forward_queue_weight = source_phantom.GetForwardWeightPlusOffset(); - // const int reverse_queue_weight = target_phantom.GetForwardWeightPlusOffset(); - // const int weight_diff = (forward_queue_weight - reverse_queue_weight); - // SimpleLogger().Write(logDEBUG) << "fwd queue offset: " << std::max(0, weight_diff); - // return 0;//std::max(0, weight_diff); - // } - // return 0; - // } - - // bool ComputeReverseQueueOffset() const - // { - // if (source_phantom.reverse_node_id == target_phantom.reverse_node_id) - // { - // const int forward_queue_weight = source_phantom.GetReverseWeightPlusOffset(); - // const int reverse_queue_weight = target_phantom.GetReverseWeightPlusOffset(); - // const int weight_diff = (forward_queue_weight - reverse_queue_weight); - // SimpleLogger().Write(logDEBUG) << "rev queue offset: " << std::max(0, weight_diff); - // return 0;//std::max(0, weight_diff); - // } - // return 0; - // } }; inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) diff --git a/Descriptors/DescriptionFactory.cpp b/Descriptors/DescriptionFactory.cpp index be69d5fb8..1db3fca2e 100644 --- a/Descriptors/DescriptionFactory.cpp +++ b/Descriptors/DescriptionFactory.cpp @@ -60,20 +60,11 @@ double DescriptionFactory::GetBearing(const FixedPointCoordinate & A, const Fixe { result -= 360.; } - - // SimpleLogger().Write(logDEBUG) << "bearing between " << A << " and " << B << " is " << result; - return result; } void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool source_traversed_in_reverse) { - // int fwd_weight = source.forward_weight; - // int rev_weight = source.reverse_weight; - // int fwd_offset = source.forward_offset; - // int rev_offset = source.reverse_offset; - // SimpleLogger().Write(logDEBUG) << "df source, traversed in reverse: " << (source_traversed_in_reverse ? "y" : "n") << ", location: " << source.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - // SimpleLogger().Write(logDEBUG) << "duration of first segment: " << (source_traversed_in_reverse ? source.GetReverseWeightPlusOffset() : source.GetForwardWeightPlusOffset()); start_phantom = source; AppendSegment( source.location, @@ -83,13 +74,6 @@ void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool void DescriptionFactory::SetEndSegment(const PhantomNode & target, const bool target_traversed_in_reverse) { - // int fwd_weight = target.forward_weight; - // int rev_weight = target.reverse_weight; - // int fwd_offset = target.forward_offset; - // int rev_offset = target.reverse_offset; - // SimpleLogger().Write(logDEBUG) << "df target, traversed in reverse: " << (target_traversed_in_reverse ? "y" : "n") << ", location: " << target.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset; - // SimpleLogger().Write(logDEBUG) << "duration of last segment: " << (target_traversed_in_reverse ? target.GetReverseWeightPlusOffset() : target.GetForwardWeightPlusOffset()); - target_phantom = target; pathDescription.push_back( SegmentInformation( @@ -152,9 +136,5 @@ 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/RoutingAlgorithms/AlternativePathRouting.h b/RoutingAlgorithms/AlternativePathRouting.h index adc97126e..9d5983c8c 100644 --- a/RoutingAlgorithms/AlternativePathRouting.h +++ b/RoutingAlgorithms/AlternativePathRouting.h @@ -148,17 +148,6 @@ public: ); } - // const int forward_offset = phantom_node_pair.ComputeForwardQueueOffset(); - // const int forward_offset = super::ComputeEdgeOffset( - // phantom_node_pair.source_phantom - // ); - // const int reverse_offset = phantom_node_pair.ComputeReverseQueueOffset(); - // const int reverse_offset = super::ComputeEdgeOffset( - // phantom_node_pair.target_phantom - // ); - - // SimpleLogger().Write(logDEBUG) << "fwd_offset: " << forward_offset << ", reverse_offset: " << reverse_offset; - //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()){ @@ -183,9 +172,7 @@ public: } } - // SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; sort_unique_resize( via_node_candidate_list ); - // SimpleLogger().Write(logDEBUG) << "found " << via_node_candidate_list.size() << " unique via node candidates"; std::vector packed_forward_path; std::vector packed_reverse_path; @@ -203,8 +190,6 @@ public: //TODO: leave early when no path found: - // SimpleLogger().Write(logDEBUG) << "ub: " << upper_bound_to_shortest_path_distance; - boost::unordered_map approximated_forward_sharing; boost::unordered_map approximated_reverse_sharing; @@ -315,19 +300,6 @@ public: { BOOST_ASSERT(!packed_shortest_path.empty()); raw_route_data.unpacked_path_segments.resize(1); - // SimpleLogger().Write() << "fwd offset1: " << phantom_node_pair.source_phantom.fwd_segment_position; - // SimpleLogger().Write() << "fwd offset2: " << phantom_node_pair.source_phantom.rev_segment_position; - // SimpleLogger().Write() << "rev offset1: " << phantom_node_pair.target_phantom.fwd_segment_position; - // SimpleLogger().Write() << "rev offset2: " << phantom_node_pair.target_phantom.rev_segment_position; - - // int start_offset = ( packed_shortest_path.front() == phantom_node_pair.source_phantom.forward_node_id ? 1 : -1 )*phantom_node_pair.source_phantom.fwd_segment_position; - // SimpleLogger().Write(logDEBUG) << "unpacking from index " << phantom_node_pair.source_phantom.fwd_segment_position; - - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.source_phantom.forward_node_id: " << phantom_node_pair.source_phantom.forward_node_id; - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.source_phantom.reverse_node_id: " << phantom_node_pair.source_phantom.reverse_node_id; - // SimpleLogger().Write(logDEBUG) << "phantom_node_pair.target_phantom.packed_geometry_id: " << phantom_node_pair.target_phantom.packed_geometry_id; - // SimpleLogger().Write(logDEBUG) << "packed_shortest_path.back(): " << packed_shortest_path.back(); - raw_route_data.source_traversed_in_reverse = (packed_shortest_path.front() != phantom_node_pair.source_phantom.forward_node_id); raw_route_data.target_traversed_in_reverse = (packed_shortest_path.back() != phantom_node_pair.target_phantom.forward_node_id); @@ -340,7 +312,6 @@ public: raw_route_data.unpacked_path_segments.front() ); raw_route_data.lengthOfShortestPath = upper_bound_to_shortest_path_distance; - // SimpleLogger().Write(logDEBUG) << "upper_bound_to_shortest_path_distance: " << upper_bound_to_shortest_path_distance; } if( SPECIAL_NODEID != selected_via_node ) { @@ -367,7 +338,6 @@ public: ); raw_route_data.lengthOfAlternativePath = length_of_via_path; - // SimpleLogger().Write(logDEBUG) << "length_of_via_path: " << length_of_via_path; } } From 78f5753a3adf5d9b719289792398f3589350f0fb Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 14:42:06 +0200 Subject: [PATCH 86/89] fix signed/unsigned comparison --- RoutingAlgorithms/BasicRoutingInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 04913a38e..878c4251e 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -239,7 +239,7 @@ public: BOOST_ASSERT( start_index >= 0 ); BOOST_ASSERT( start_index <= end_index ); for( - unsigned i = start_index; + int i = start_index; i < end_index; ++i ) { From 51e8113a69553adc1c075762eb92f88f1f03f131 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 15:24:18 +0200 Subject: [PATCH 87/89] make tests use fuzzy matching instead of tweaked expectations --- features/car/maxspeed.feature | 28 ++++++++++++++-------------- features/car/speed.feature | 30 +++++++++++++++--------------- features/testbot/opposite.feature | 6 +++--- features/testbot/speed.feature | 6 +++--- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/features/car/maxspeed.feature b/features/car/maxspeed.feature index f3771cc2b..d32e3205f 100644 --- a/features/car/maxspeed.feature +++ b/features/car/maxspeed.feature @@ -16,9 +16,9 @@ When a max speed is set, osrm will use 2/3 of that as the actual speed. | bc | trunk | 60 | When I route I should get - | from | to | route | speed | - | a | b | ab | 85 km/h | - | b | c | bc | 39 km/h | + | from | to | route | speed | + | a | b | ab | 85 km/h | + | b | c | bc | 40 km/h +- 1 | Scenario: Car - Do not ignore maxspeed when higher than way speed Given the node map @@ -30,22 +30,22 @@ When a max speed is set, osrm will use 2/3 of that as the actual speed. | bc | residential | 90 | When I route I should get - | from | to | route | speed | - | a | b | ab | 25 km/h | - | b | c | bc | 59 km/h | + | from | to | route | speed | + | a | b | ab | 25 km/h | + | b | c | bc | 60 km/h +- 1 | Scenario: Car - Forward/backward maxspeed Given a grid size of 100 meters Then routability should be - | highway | maxspeed | maxspeed:forward | maxspeed:backward | forw | backw | - | primary | | | | 65 km/h | 65 km/h | - | primary | 60 | | | 40 km/h | 40 km/h | - | primary | | 60 | | 40 km/h | 65 km/h | - | primary | | | 60 | 65 km/h | 40 km/h | - | primary | 15 | 60 | | 40 km/h | 9 km/h | - | primary | 15 | | 60 | 9 km/h | 40 km/h | - | primary | 15 | 30 | 60 | 20 km/h | 40 km/h | + | highway | maxspeed | maxspeed:forward | maxspeed:backward | forw | backw | + | primary | | | | 65 km/h | 65 km/h | + | primary | 60 | | | 40 km/h | 40 km/h | + | primary | | 60 | | 40 km/h | 65 km/h | + | primary | | | 60 | 65 km/h | 40 km/h | + | primary | 15 | 60 | | 40 km/h | 10 km/h +- 1 | + | primary | 15 | | 60 | 10 km/h +- 1| 40 km/h | + | primary | 15 | 30 | 60 | 20 km/h | 40 km/h | Scenario: Car - Maxspeed should not allow routing on unroutable ways Then routability should be diff --git a/features/car/speed.feature b/features/car/speed.feature index a7a614a19..4df30ed4d 100644 --- a/features/car/speed.feature +++ b/features/car/speed.feature @@ -7,18 +7,18 @@ Feature: Car - speeds Scenario: Car - speed of various way types Then routability should be - | highway | oneway | bothw | - | motorway | no | 90 km/h | - | motorway_link | no | 75 km/h | - | trunk | no | 84 km/h | - | trunk_link | no | 69 km/h | - | primary | no | 64 km/h | - | primary_link | no | 60 km/h | - | secondary | no | 54 km/h | - | secondary_link | no | 50 km/h | - | tertiary | no | 40 km/h | - | tertiary_link | no | 30 km/h | - | unclassified | no | 25 km/h | - | residential | no | 25 km/h | - | living_street | no | 10 km/h | - | service | no | 15 km/h | + | highway | oneway | bothw | + | motorway | no | 90 km/h | + | motorway_link | no | 75 km/h | + | trunk | no | 85 km/h +- 1 | + | trunk_link | no | 70 km/h +- 1 | + | primary | no | 65 km/h +- 1 | + | primary_link | no | 60 km/h | + | secondary | no | 55 km/h +- 1 | + | secondary_link | no | 50 km/h | + | tertiary | no | 40 km/h | + | tertiary_link | no | 30 km/h | + | unclassified | no | 25 km/h | + | residential | no | 25 km/h | + | living_street | no | 10 km/h | + | service | no | 15 km/h | diff --git a/features/testbot/opposite.feature b/features/testbot/opposite.feature index 9fdce5675..c19755cdc 100644 --- a/features/testbot/opposite.feature +++ b/features/testbot/opposite.feature @@ -13,6 +13,6 @@ Feature: Separate settings for forward/backward direction | abcd | river | When I route I should get - | from | to | route | distance | speed | - | a | d | abcd | 300 +- 1m | 36 km/h | - | d | a | abcd | 300 +- 1m | 15 km/h | + | from | to | route | distance | speed | + | a | d | abcd | 300 +- 1m | 36 km/h | + | d | a | abcd | 300 +- 1m | 16 km/h +- 1 | diff --git a/features/testbot/speed.feature b/features/testbot/speed.feature index 81674e944..2eb3724f5 100644 --- a/features/testbot/speed.feature +++ b/features/testbot/speed.feature @@ -26,6 +26,6 @@ Feature: Testbot - speeds | ab | river | When I route I should get - | from | to | route | speed | time | distance | - | a | b | ab | 36 km/h | 10s | 100m | - | b | a | ab | 15 km/h | 23s | 100m | + | from | to | route | speed | time | distance | + | a | b | ab | 36 km/h | 10s | 100m | + | b | a | ab | 16 km/h +- 1 | 23s | 100m | From e0027a78e1876c6040840954bff5d221a8b0ddc0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 15:48:10 +0200 Subject: [PATCH 88/89] fix signed unsigned comparison --- RoutingAlgorithms/BasicRoutingInterface.h | 171 +++++++++------------- 1 file changed, 67 insertions(+), 104 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 878c4251e..2aa6cc6c0 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -125,15 +125,13 @@ public: //New Node discovered -> Add to Heap + Node Info Storage if ( !forward_heap.WasInserted( to ) ) { - // SimpleLogger().Write() << "insert (" << node << "," << to << "), distance: " << to_distance << ", edge id: " << edge; forward_heap.Insert( to, to_distance, node ); } //Found a shorter Path -> Update distance else if ( to_distance < forward_heap.GetKey( to ) ) { + //new parent forward_heap.GetData( to ).parent = node; forward_heap.DecreaseKey( to, to_distance ); - // SimpleLogger().Write() << "decrease (" << node << "," << to << "), distance: " << to_distance; - //new parent } } } @@ -160,8 +158,8 @@ public: } std::pair edge; - while(!recursion_stack.empty()) { - // bool segment_reversed = false; + while (!recursion_stack.empty()) + { edge = recursion_stack.top(); recursion_stack.pop(); @@ -169,56 +167,47 @@ public: // The above explanation unclear? Think! EdgeID smaller_edge_id = SPECIAL_EDGEID; int edge_weight = INT_MAX; - for( - EdgeID edge_id = facade->BeginEdges(edge.first); - edge_id < facade->EndEdges(edge.first); - ++edge_id - ){ + 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(edge_id) == edge.second) && + if ((facade->GetTarget(edge_id) == edge.second) && (weight < edge_weight) && - facade->GetEdgeData(edge_id).forward - ){ + facade->GetEdgeData(edge_id).forward) + { smaller_edge_id = edge_id; edge_weight = weight; } } - if( SPECIAL_EDGEID == smaller_edge_id ){ - // SimpleLogger().Write() << "checking reverse"; - for( - EdgeID edge_id = facade->BeginEdges(edge.second); - edge_id < facade->EndEdges(edge.second); - ++edge_id - ){ + if (SPECIAL_EDGEID == smaller_edge_id) + { + 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(edge_id) == edge.first) && - (weight < edge_weight) && - facade->GetEdgeData(edge_id).backward - ){ + if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && facade->GetEdgeData(edge_id).backward) + { smaller_edge_id = edge_id; edge_weight = weight; } } } - BOOST_ASSERT_MSG(edge_weight != SPECIAL_EDGEID, "edge id invalid"); + BOOST_ASSERT_MSG(edge_weight != INVALID_EDGE_WEIGHT, "edge id invalid"); - - // BOOST_ASSERT( facade->EndEdges(edge.first) != smaller_edge_id ); - - const EdgeData& ed = facade->GetEdgeData(smaller_edge_id); - if( ed.shortcut ) {//unpack + 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 recursion_stack.push(std::make_pair(middle_node_id, edge.second)); recursion_stack.push(std::make_pair(edge.first, middle_node_id)); - } else { + } + else + { BOOST_ASSERT_MSG(!ed.shortcut, "original edge flagged as shortcut"); unsigned name_index = facade->GetNameIndexFromEdgeID(ed.id); const TurnInstruction turn_instruction = facade->GetTurnInstructionForEdgeID(ed.id); - if ( !facade->EdgeIsCompressed(ed.id) ){ + if (!facade->EdgeIsCompressed(ed.id)) + { BOOST_ASSERT( !facade->EdgeIsCompressed(ed.id) ); unpacked_path.push_back( PathData( @@ -228,21 +217,19 @@ public: ed.distance ) ); - } else { + } + else + { std::vector id_vector; facade->GetUncompressedGeometry(facade->GetGeometryIndexForEdgeID(ed.id), id_vector); const int start_index = ( unpacked_path.empty() ? ( ( start_traversed_in_reverse ) ? id_vector.size() - phantom_node_pair.source_phantom.fwd_segment_position - 1 : phantom_node_pair.source_phantom.fwd_segment_position ) : 0 ); const int end_index = id_vector.size(); - std::string name = facade->GetEscapedNameForNameID(name_index); - BOOST_ASSERT( start_index >= 0 ); - BOOST_ASSERT( start_index <= end_index ); - for( - int i = start_index; - i < end_index; - ++i - ) { + BOOST_ASSERT(start_index >= 0); + BOOST_ASSERT(start_index <= end_index); + for (int i = start_index; i < end_index; ++i) + { unpacked_path.push_back( PathData( id_vector[i], @@ -257,10 +244,12 @@ public: } } } - if(SPECIAL_EDGEID != phantom_node_pair.target_phantom.packed_geometry_id ) { + if (SPECIAL_EDGEID != phantom_node_pair.target_phantom.packed_geometry_id) + { std::vector id_vector; facade->GetUncompressedGeometry(phantom_node_pair.target_phantom.packed_geometry_id, id_vector); - if( target_traversed_in_reverse ) { + if (target_traversed_in_reverse) + { std::reverse(id_vector.begin(), id_vector.end() ); } const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id == phantom_node_pair.target_phantom.packed_geometry_id) && unpacked_path.empty(); @@ -282,12 +271,9 @@ public: } } - BOOST_ASSERT( start_index >= 0 ); - for( - int i = start_index; - i != end_index; - ( start_index < end_index ? ++i :--i) - ) { + BOOST_ASSERT(start_index >= 0); + for (int i = start_index; i != end_index; (start_index < end_index ? ++i :--i)) + { BOOST_ASSERT( i >= -1 ); unpacked_path.push_back( PathData( @@ -321,26 +307,21 @@ public: } } - inline void UnpackEdge( - const NodeID s, - const NodeID t, - std::vector & unpacked_path - ) const { + 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(!recursion_stack.empty()) { + while (!recursion_stack.empty()) + { edge = recursion_stack.top(); recursion_stack.pop(); EdgeID smaller_edge_id = SPECIAL_EDGEID; int edge_weight = INT_MAX; - for( - EdgeID edge_id = facade->BeginEdges(edge.first); - edge_id < facade->EndEdges(edge.first); - ++edge_id - ){ + 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(edge_id) == edge.second) && @@ -352,18 +333,13 @@ public: } } - if( SPECIAL_EDGEID == smaller_edge_id ){ - for( - EdgeID edge_id = facade->BeginEdges(edge.second); - edge_id < facade->EndEdges(edge.second); - ++edge_id - ){ + if (SPECIAL_EDGEID == smaller_edge_id) + { + 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(edge_id) == edge.first) && - (weight < edge_weight) && - facade->GetEdgeData(edge_id).backward - ){ + if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && facade->GetEdgeData(edge_id).backward) + { smaller_edge_id = edge_id; edge_weight = weight; } @@ -372,16 +348,15 @@ public: BOOST_ASSERT_MSG(edge_weight != INT_MAX, "edge weight invalid"); const 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) - ); - recursion_stack.push( - std::make_pair(edge.first, middle_node_id) - ); - } else { + 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 ); } @@ -394,49 +369,37 @@ public: const SearchEngineData::QueryHeap & reverse_heap, const NodeID middle_node_id, std::vector & packed_path - ) const { + ) const + { NodeID current_node_id = middle_node_id; - while(current_node_id != forward_heap.GetData(current_node_id).parent) { + 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); } - // SimpleLogger().Write() << "parent of last node. " << forward_heap.GetData(current_node_id).parent; 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){ + 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); } } -//TODO: reorder parameters inline void RetrievePackedPathFromSingleHeap( - SearchEngineData::QueryHeap & search_heap, + const SearchEngineData::QueryHeap & search_heap, const NodeID middle_node_id, std::vector& packed_path - ) const { + ) const + { NodeID current_node_id = middle_node_id; - while(current_node_id != search_heap.GetData(current_node_id).parent) { + 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); } } - - // int ComputeOffset(const PhantomNode & phantom_node) const { - // int weight_offset = 0; - // if (phantom_node.forward_node_id != SPECIAL_NODEID) - // { - // weight_offset += phantom_node.GetForwardWeightPlusOffset(); - // } - // if (phantom_node.reverse_node_id != SPECIAL_NODEID) - // { - // weight_offset += phantom_node.GetReverseWeightPlusOffset(); - // } - // return weight_offset; - // // return phantom_node.forward_weight + (phantom_node.isBidirected() ? phantom_node.reverse_weight : 0); - // } - }; #endif /* BASICROUTINGINTERFACE_H_ */ From 9a153708e6fb33504e8b2ca0a45d267564a9f44a Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Fri, 25 Apr 2014 16:00:39 +0200 Subject: [PATCH 89/89] minor reformatting / shaping up --- RoutingAlgorithms/BasicRoutingInterface.h | 41 ++++++++++------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/RoutingAlgorithms/BasicRoutingInterface.h b/RoutingAlgorithms/BasicRoutingInterface.h index 2aa6cc6c0..e26b504cb 100644 --- a/RoutingAlgorithms/BasicRoutingInterface.h +++ b/RoutingAlgorithms/BasicRoutingInterface.h @@ -87,35 +87,33 @@ public: } //Stalling - for( - EdgeID edge = facade->BeginEdges( node ); - edge < facade->EndEdges(node); - ++edge - ) { + for (EdgeID edge = facade->BeginEdges( node ); edge < facade->EndEdges(node); ++edge) + { const EdgeData & data = facade->GetEdgeData(edge); - const bool reverse_flag = (!forward_direction) ? data.forward : data.backward; - if( reverse_flag ) { + 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; - BOOST_ASSERT_MSG( edge_weight > 0, "edge_weight invalid" ); + BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid"); - if(forward_heap.WasInserted( to )) { - if(forward_heap.GetKey( to ) + edge_weight < distance) { + if (forward_heap.WasInserted(to)) + { + if(forward_heap.GetKey( to ) + edge_weight < distance) + { return; } } } } - for( - EdgeID edge = facade->BeginEdges(node), end_edge = facade->EndEdges(node); - edge < end_edge; - ++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 ) { + bool forward_directionFlag = (forward_direction ? data.forward : data.backward); + if (forward_directionFlag) + { const NodeID to = facade->GetTarget(edge); const int edge_weight = data.distance; @@ -137,13 +135,8 @@ public: } } - - //TODO: refactor parameters to only edge ids for start and end - inline void UnpackPath( - const std::vector & packed_path, - const PhantomNodes & phantom_node_pair, - std::vector & unpacked_path - ) const { + inline void UnpackPath(const std::vector & packed_path, const PhantomNodes & phantom_node_pair, std::vector & unpacked_path) const + { const bool start_traversed_in_reverse = (packed_path.front() != phantom_node_pair.source_phantom.forward_node_id); const bool target_traversed_in_reverse = (packed_path.back() != phantom_node_pair.target_phantom.forward_node_id);