Add namespace around all files

This commit is contained in:
Patrick Niklaus
2016-01-05 16:51:13 +01:00
parent efc9007cbf
commit 6b18e4f7e9
194 changed files with 2648 additions and 1245 deletions
+41 -38
View File
@@ -26,7 +26,9 @@
#include <string>
#include <vector>
namespace
namespace osrm
{
namespace tools
{
struct TarjanEdgeData
@@ -37,7 +39,7 @@ struct TarjanEdgeData
unsigned name_id;
};
using TarjanGraph = StaticGraph<TarjanEdgeData>;
using TarjanGraph = util::StaticGraph<TarjanEdgeData>;
using TarjanEdge = TarjanGraph::InputEdge;
void deleteFileIfExists(const std::string &file_name)
@@ -47,27 +49,26 @@ void deleteFileIfExists(const std::string &file_name)
boost::filesystem::remove(file_name);
}
}
}
std::size_t loadGraph(const char *path,
std::vector<QueryNode> &coordinate_list,
std::vector<extractor::QueryNode> &coordinate_list,
std::vector<TarjanEdge> &graph_edge_list)
{
std::ifstream input_stream(path, std::ifstream::in | std::ifstream::binary);
if (!input_stream.is_open())
{
throw osrm::exception("Cannot open osrm file");
throw util::exception("Cannot open osrm file");
}
// load graph data
std::vector<NodeBasedEdge> edge_list;
std::vector<extractor::NodeBasedEdge> edge_list;
std::vector<NodeID> traffic_light_node_list;
std::vector<NodeID> barrier_node_list;
auto number_of_nodes = loadNodesFromFile(input_stream, barrier_node_list,
auto number_of_nodes = util::loadNodesFromFile(input_stream, barrier_node_list,
traffic_light_node_list, coordinate_list);
loadEdgesFromFile(input_stream, edge_list);
util::loadEdgesFromFile(input_stream, edge_list);
traffic_light_node_list.clear();
traffic_light_node_list.shrink_to_fit();
@@ -94,46 +95,48 @@ std::size_t loadGraph(const char *path,
return number_of_nodes;
}
}
}
int main(int argc, char *argv[])
{
std::vector<QueryNode> coordinate_list;
std::vector<osrm::extractor::QueryNode> coordinate_list;
LogPolicy::GetInstance().Unmute();
osrm::util::LogPolicy::GetInstance().Unmute();
try
{
// enable logging
if (argc < 2)
{
SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
osrm::util::SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0] << " <osrm>";
return -1;
}
std::vector<TarjanEdge> graph_edge_list;
auto number_of_nodes = loadGraph(argv[1], coordinate_list, graph_edge_list);
std::vector<osrm::tools::TarjanEdge> graph_edge_list;
auto number_of_nodes = osrm::tools::loadGraph(argv[1], coordinate_list, graph_edge_list);
tbb::parallel_sort(graph_edge_list.begin(), graph_edge_list.end());
const auto graph = std::make_shared<TarjanGraph>(number_of_nodes, graph_edge_list);
const auto graph = std::make_shared<osrm::tools::TarjanGraph>(number_of_nodes, graph_edge_list);
graph_edge_list.clear();
graph_edge_list.shrink_to_fit();
SimpleLogger().Write() << "Starting SCC graph traversal";
osrm::util::SimpleLogger().Write() << "Starting SCC graph traversal";
auto tarjan = osrm::make_unique<TarjanSCC<TarjanGraph>>(graph);
auto tarjan = osrm::util::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
tarjan->run();
SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
osrm::util::SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
<< " many components";
SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs";
osrm::util::SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs";
// output
TIMER_START(SCC_RUN_SETUP);
// remove files from previous run if exist
deleteFileIfExists("component.dbf");
deleteFileIfExists("component.shx");
deleteFileIfExists("component.shp");
osrm::tools::deleteFileIfExists("component.dbf");
osrm::tools::deleteFileIfExists("component.shx");
osrm::tools::deleteFileIfExists("component.shp");
Percent percentage(graph->GetNumberOfNodes());
osrm::util::Percent percentage(graph->GetNumberOfNodes());
OGRRegisterAll();
@@ -142,13 +145,13 @@ int main(int argc, char *argv[])
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(psz_driver_name);
if (nullptr == po_driver)
{
throw osrm::exception("ESRI Shapefile driver not available");
throw osrm::util::exception("ESRI Shapefile driver not available");
}
auto *po_datasource = po_driver->CreateDataSource("component.shp", nullptr);
if (nullptr == po_datasource)
{
throw osrm::exception("Creation of output file failed");
throw osrm::util::exception("Creation of output file failed");
}
auto *po_srs = new OGRSpatialReference();
@@ -158,26 +161,26 @@ int main(int argc, char *argv[])
if (nullptr == po_layer)
{
throw osrm::exception("Layer creation failed.");
throw osrm::util::exception("Layer creation failed.");
}
TIMER_STOP(SCC_RUN_SETUP);
SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000.
osrm::util::SimpleLogger().Write() << "shapefile setup took " << TIMER_MSEC(SCC_RUN_SETUP) / 1000.
<< "s";
uint64_t total_network_length = 0;
percentage.reinit(graph->GetNumberOfNodes());
TIMER_START(SCC_OUTPUT);
for (const NodeID source : osrm::irange(0u, graph->GetNumberOfNodes()))
for (const NodeID source : osrm::util::irange(0u, graph->GetNumberOfNodes()))
{
percentage.printIncrement();
for (const auto current_edge : graph->GetAdjacentEdgeRange(source))
{
const TarjanGraph::NodeIterator target = graph->GetTarget(current_edge);
const auto target = graph->GetTarget(current_edge);
if (source < target || SPECIAL_EDGEID == graph->FindEdge(target, source))
{
total_network_length +=
100 * coordinate_calculation::greatCircleDistance(
100 * osrm::util::coordinate_calculation::greatCircleDistance(
coordinate_list[source].lat, coordinate_list[source].lon,
coordinate_list[target].lat, coordinate_list[target].lon);
@@ -193,17 +196,17 @@ int main(int argc, char *argv[])
if (size_of_containing_component < 1000)
{
OGRLineString line_string;
line_string.addPoint(coordinate_list[source].lon / COORDINATE_PRECISION,
coordinate_list[source].lat / COORDINATE_PRECISION);
line_string.addPoint(coordinate_list[target].lon / COORDINATE_PRECISION,
coordinate_list[target].lat / COORDINATE_PRECISION);
line_string.addPoint(coordinate_list[source].lon / osrm::COORDINATE_PRECISION,
coordinate_list[source].lat / osrm::COORDINATE_PRECISION);
line_string.addPoint(coordinate_list[target].lon / osrm::COORDINATE_PRECISION,
coordinate_list[target].lat / osrm::COORDINATE_PRECISION);
OGRFeature *po_feature = OGRFeature::CreateFeature(po_layer->GetLayerDefn());
po_feature->SetGeometry(&line_string);
if (OGRERR_NONE != po_layer->CreateFeature(po_feature))
{
throw osrm::exception("Failed to create feature in shapefile.");
throw osrm::util::exception("Failed to create feature in shapefile.");
}
OGRFeature::DestroyFeature(po_feature);
}
@@ -213,18 +216,18 @@ int main(int argc, char *argv[])
OGRSpatialReference::DestroySpatialReference(po_srs);
OGRDataSource::DestroyDataSource(po_datasource);
TIMER_STOP(SCC_OUTPUT);
SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000.
osrm::util::SimpleLogger().Write() << "generating output took: " << TIMER_MSEC(SCC_OUTPUT) / 1000.
<< "s";
SimpleLogger().Write() << "total network distance: "
osrm::util::SimpleLogger().Write() << "total network distance: "
<< static_cast<uint64_t>(total_network_length / 100 / 1000.)
<< " km";
SimpleLogger().Write() << "finished component analysis";
osrm::util::SimpleLogger().Write() << "finished component analysis";
}
catch (const std::exception &e)
{
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
osrm::util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
}
return 0;
}