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);