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