adapt tiny_components.hpp to have the same interface as bfs_components.hpp

This commit is contained in:
Dennis Luxen 2014-12-22 16:43:57 +01:00
parent ccc4607d6d
commit a5c824f694
3 changed files with 24 additions and 98 deletions

View File

@ -60,9 +60,11 @@ add_library(PHANTOMNODE OBJECT data_structures/phantom_node.cpp)
set(ExtractorSources extract.cpp ${ExtractorGlob}) set(ExtractorSources extract.cpp ${ExtractorGlob})
add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER>) add_executable(osrm-extract ${ExtractorSources} $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER>)
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp data_structures/restriction_map.cpp Util/compute_angle.cpp) add_library(RESTRICTION OBJECT data_structures/restriction_map.cpp)
file(GLOB PrepareGlob contractor/*.cpp data_structures/hilbert_value.cpp Util/compute_angle.cpp {RestrictionMapGlob})
set(PrepareSources prepare.cpp ${PrepareGlob}) set(PrepareSources prepare.cpp ${PrepareGlob})
add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER>) add_executable(osrm-prepare ${PrepareSources} $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION>)
file(GLOB ServerGlob Server/*.cpp) file(GLOB ServerGlob Server/*.cpp)
file(GLOB DescriptorGlob descriptors/*.cpp) file(GLOB DescriptorGlob descriptors/*.cpp)
@ -280,7 +282,7 @@ if(WITH_TOOLS OR BUILD_TOOLS)
message(STATUS "Activating OSRM internal tools") message(STATUS "Activating OSRM internal tools")
find_package(GDAL) find_package(GDAL)
if(GDAL_FOUND) if(GDAL_FOUND)
add_executable(osrm-components tools/components.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER>) add_executable(osrm-components tools/components.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION>)
target_link_libraries(osrm-components ${TBB_LIBRARIES}) target_link_libraries(osrm-components ${TBB_LIBRARIES})
include_directories(${GDAL_INCLUDE_DIR}) include_directories(${GDAL_INCLUDE_DIR})
target_link_libraries( target_link_libraries(

View File

@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../data_structures/query_node.hpp" #include "../data_structures/query_node.hpp"
#include "../data_structures/percent.hpp" #include "../data_structures/percent.hpp"
#include "../data_structures/restriction.hpp" #include "../data_structures/restriction.hpp"
#include "../data_structures/restriction_map.hpp"
#include "../data_structures/turn_instructions.hpp" #include "../data_structures/turn_instructions.hpp"
#include "../Util/integer_range.hpp" #include "../Util/integer_range.hpp"
@ -75,64 +76,23 @@ class TarjanSCC
bool on_stack; bool on_stack;
}; };
using RestrictionSource = std::pair<NodeID, NodeID>;
using RestrictionTarget = std::pair<NodeID, bool>;
using EmanatingRestrictionsVector = std::vector<RestrictionTarget>;
using RestrictionMap = std::unordered_map<RestrictionSource, unsigned>;
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
std::vector<unsigned> components_index; std::vector<unsigned> components_index;
std::vector<NodeID> component_size_vector; std::vector<NodeID> component_size_vector;
std::shared_ptr<GraphT> m_node_based_graph; std::shared_ptr<GraphT> m_node_based_graph;
std::unordered_set<NodeID> barrier_node_list; std::unordered_set<NodeID> barrier_node_set;
unsigned size_one_counter;
RestrictionMap m_restriction_map; RestrictionMap m_restriction_map;
unsigned size_one_counter;
public: public:
TarjanSCC(std::shared_ptr<GraphT> graph, TarjanSCC(std::shared_ptr<GraphT> graph,
std::vector<NodeID> &bn, const RestrictionMap &restrictions,
std::vector<TurnRestriction> &irs) const std::vector<NodeID> &barrier_nodes)
: components_index(graph->GetNumberOfNodes(), SPECIAL_NODEID), : components_index(graph->GetNumberOfNodes(), SPECIAL_NODEID),
m_node_based_graph(graph), m_node_based_graph(graph), m_restriction_map(restrictions),
size_one_counter(0) size_one_counter(0)
{ {
barrier_node_set.insert(std::begin(barrier_nodes), std::end(barrier_nodes));
TIMER_START(SCC_LOAD); BOOST_ASSERT(m_node_based_graph->GetNumberOfNodes() > 0);
for (const TurnRestriction &restriction : irs)
{
std::pair<NodeID, NodeID> restriction_source = {restriction.from.node,
restriction.via.node};
unsigned index = 0;
const auto restriction_iterator = m_restriction_map.find(restriction_source);
if (restriction_iterator == m_restriction_map.end())
{
index = m_restriction_bucket_list.size();
m_restriction_bucket_list.resize(index + 1);
m_restriction_map.emplace(restriction_source, index);
}
else
{
index = restriction_iterator->second;
// Map already contains an is_only_*-restriction
if (m_restriction_bucket_list.at(index).begin()->second)
{
continue;
}
else if (restriction.flags.is_only)
{
// We are going to insert an is_only_*-restriction. There can be only one.
m_restriction_bucket_list.at(index).clear();
}
}
m_restriction_bucket_list.at(index)
.emplace_back(restriction.to.node, restriction.flags.is_only);
}
barrier_node_list.insert(bn.begin(), bn.end());
TIMER_STOP(SCC_LOAD);
SimpleLogger().Write() << "Loading data into SCC took " << TIMER_MSEC(SCC_LOAD)/1000. << "s";
} }
void Run() void Run()
@ -253,44 +213,6 @@ class TarjanSCC
{ {
return component_size_vector[components_index[node]]; return component_size_vector[components_index[node]];
} }
private:
unsigned CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const
{
std::pair<NodeID, NodeID> restriction_source = {u, v};
const auto restriction_iterator = m_restriction_map.find(restriction_source);
if (restriction_iterator != m_restriction_map.end())
{
const unsigned index = restriction_iterator->second;
for (const RestrictionSource &restriction_target : m_restriction_bucket_list.at(index))
{
if (restriction_target.second)
{
return restriction_target.first;
}
}
}
return SPECIAL_NODEID;
}
bool CheckIfTurnIsRestricted(const NodeID u, 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.
std::pair<NodeID, NodeID> restriction_source = {u, v};
const auto restriction_iterator = m_restriction_map.find(restriction_source);
if (restriction_iterator != m_restriction_map.end())
{
const unsigned index = restriction_iterator->second;
for (const RestrictionTarget &restriction_target : m_restriction_bucket_list.at(index))
{
if (w == restriction_target.first)
{
return true;
}
}
}
return false;
}
}; };
#endif /* TINY_COMPONENTS_HPP */ #endif /* TINY_COMPONENTS_HPP */

View File

@ -52,7 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector> #include <vector>
std::vector<QueryNode> coordinate_list; std::vector<QueryNode> coordinate_list;
std::vector<TurnRestriction> restrictions_vector; std::vector<TurnRestriction> restriction_list;
std::vector<NodeID> bollard_node_list; std::vector<NodeID> bollard_node_list;
std::vector<NodeID> traffic_lights_list; std::vector<NodeID> traffic_lights_list;
@ -107,12 +107,12 @@ int main(int argc, char *argv[])
} }
uint32_t usable_restrictions = 0; uint32_t usable_restrictions = 0;
restriction_ifstream.read((char *)&usable_restrictions, sizeof(uint32_t)); restriction_ifstream.read((char *)&usable_restrictions, sizeof(uint32_t));
restrictions_vector.resize(usable_restrictions); restriction_list.resize(usable_restrictions);
// load restrictions // load restrictions
if (usable_restrictions > 0) if (usable_restrictions > 0)
{ {
restriction_ifstream.read((char *)&(restrictions_vector[0]), restriction_ifstream.read((char *)&(restriction_list[0]),
usable_restrictions * sizeof(TurnRestriction)); usable_restrictions * sizeof(TurnRestriction));
} }
restriction_ifstream.close(); restriction_ifstream.close();
@ -130,14 +130,14 @@ int main(int argc, char *argv[])
bollard_node_list, bollard_node_list,
traffic_lights_list, traffic_lights_list,
&coordinate_list, &coordinate_list,
restrictions_vector); restriction_list);
input_stream.close(); input_stream.close();
BOOST_ASSERT_MSG(restrictions_vector.size() == usable_restrictions, BOOST_ASSERT_MSG(restriction_list.size() == usable_restrictions,
"size of restrictions_vector changed"); "size of restriction_list changed");
SimpleLogger().Write() << restrictions_vector.size() << " restrictions, " SimpleLogger().Write() << restriction_list.size() << " restrictions, "
<< bollard_node_list.size() << " bollard nodes, " << bollard_node_list.size() << " bollard nodes, "
<< traffic_lights_list.size() << " traffic lights"; << traffic_lights_list.size() << " traffic lights";
@ -179,9 +179,11 @@ int main(int argc, char *argv[])
edge_list.shrink_to_fit(); edge_list.shrink_to_fit();
SimpleLogger().Write() << "Starting SCC graph traversal"; SimpleLogger().Write() << "Starting SCC graph traversal";
RestrictionMap restriction_map(restriction_list);
auto tarjan = osrm::make_unique<TarjanSCC<TarjanDynamicGraph>>(graph, auto tarjan = osrm::make_unique<TarjanSCC<TarjanDynamicGraph>>(graph,
bollard_node_list, restriction_map,
restrictions_vector); bollard_node_list);
tarjan->Run(); tarjan->Run();
// output // output