From baacd0e50c8ac6b35c5ac9e183d88f0c53e43b5b Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 22 Jan 2015 12:19:11 +0100 Subject: [PATCH] reformat source files --- Server/RequestHandler.cpp | 20 +-- Util/compute_angle.cpp | 6 +- contractor/edge_based_graph_factory.cpp | 140 +++++++++------------ contractor/processing_chain.cpp | 64 ++++------ data_structures/coordinate.cpp | 4 +- data_structures/coordinate_calculation.cpp | 87 ++++++------- datastore.cpp | 12 +- extractor/extraction_containers.cpp | 81 ++++++------ extractor/extraction_containers.hpp | 16 +-- extractor/extraction_node.hpp | 7 +- extractor/extraction_way.hpp | 21 ++-- extractor/extractor.cpp | 103 ++++++++------- extractor/extractor_callbacks.cpp | 86 ++++++------- extractor/extractor_options.cpp | 12 +- extractor/internal_extractor_edge.hpp | 21 ++-- extractor/restriction_parser.cpp | 4 +- extractor/restriction_parser.hpp | 3 +- extractor/scripting_environment.cpp | 72 +++++------ extractor/scripting_environment.hpp | 4 +- routed.cpp | 23 ++-- tools/components.cpp | 2 +- tools/simpleclient.cpp | 12 +- unit_tests/data_structures/coordinate.cpp | 4 +- 23 files changed, 374 insertions(+), 430 deletions(-) diff --git a/Server/RequestHandler.cpp b/Server/RequestHandler.cpp index 277298dea..6aea27d7f 100644 --- a/Server/RequestHandler.cpp +++ b/Server/RequestHandler.cpp @@ -70,14 +70,15 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply time_stamp = localtime(<ime); // log timestamp - SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday << "-" - << (time_stamp->tm_mon + 1 < 10 ? "0" : "") << (time_stamp->tm_mon + 1) << "-" - << 1900 + time_stamp->tm_year << " " << (time_stamp->tm_hour < 10 ? "0" : "") - << time_stamp->tm_hour << ":" << (time_stamp->tm_min < 10 ? "0" : "") << time_stamp->tm_min - << ":" << (time_stamp->tm_sec < 10 ? "0" : "") << time_stamp->tm_sec << " " - << req.endpoint.to_string() << " " << req.referrer - << (0 == req.referrer.length() ? "- " : " ") << req.agent - << (0 == req.agent.length() ? "- " : " ") << request; + SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday + << "-" << (time_stamp->tm_mon + 1 < 10 ? "0" : "") + << (time_stamp->tm_mon + 1) << "-" << 1900 + time_stamp->tm_year + << " " << (time_stamp->tm_hour < 10 ? "0" : "") + << time_stamp->tm_hour << ":" << (time_stamp->tm_min < 10 ? "0" : "") + << time_stamp->tm_min << ":" << (time_stamp->tm_sec < 10 ? "0" : "") + << time_stamp->tm_sec << " " << req.endpoint.to_string() << " " + << req.referrer << (0 == req.referrer.length() ? "- " : " ") + << req.agent << (0 == req.agent.length() ? "- " : " ") << request; RouteParameters route_parameters; APIGrammarParser api_parser(&route_parameters); @@ -121,7 +122,8 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply return; } // set headers - reply.headers.emplace_back("Content-Length", cast::integral_to_string(reply.content.size())); + reply.headers.emplace_back("Content-Length", + cast::integral_to_string(reply.content.size())); if ("gpx" == route_parameters.output_format) { // gpx file JSON::gpx_render(reply.content, json_result.values["route"]); diff --git a/Util/compute_angle.cpp b/Util/compute_angle.cpp index ca9d18980..5de872319 100644 --- a/Util/compute_angle.cpp +++ b/Util/compute_angle.cpp @@ -39,9 +39,11 @@ double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &A, const FixedPointCoordinate &B) { const double v1x = (A.lon - C.lon) / COORDINATE_PRECISION; - const double v1y = mercator::lat2y(A.lat / COORDINATE_PRECISION) - mercator::lat2y(C.lat / COORDINATE_PRECISION); + const double v1y = mercator::lat2y(A.lat / COORDINATE_PRECISION) - + mercator::lat2y(C.lat / COORDINATE_PRECISION); const double v2x = (B.lon - C.lon) / COORDINATE_PRECISION; - const double v2y = mercator::lat2y(B.lat / COORDINATE_PRECISION) - mercator::lat2y(C.lat / COORDINATE_PRECISION); + const double v2y = mercator::lat2y(B.lat / COORDINATE_PRECISION) - + mercator::lat2y(C.lat / COORDINATE_PRECISION); double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI; while (angle < 0.) diff --git a/contractor/edge_based_graph_factory.cpp b/contractor/edge_based_graph_factory.cpp index 144b1faaf..6d9c43412 100644 --- a/contractor/edge_based_graph_factory.cpp +++ b/contractor/edge_based_graph_factory.cpp @@ -77,10 +77,9 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector &nodes) nodes.swap(m_edge_based_node_list); } -void -EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, - const NodeID node_v, - const unsigned component_id) +void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, + const NodeID node_v, + const unsigned component_id) { // merge edges together into one EdgeBasedNode BOOST_ASSERT(node_u != SPECIAL_NODEID); @@ -172,20 +171,13 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id); // build edges - m_edge_based_node_list.emplace_back(forward_data.edgeBasedNodeID, - reverse_data.edgeBasedNodeID, - current_edge_source_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[i], - m_geometry_compressor.GetPositionForID(e1), - component_id, - i, - forward_data.travel_mode, - reverse_data.travel_mode); + m_edge_based_node_list.emplace_back( + forward_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID, + current_edge_source_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[i], m_geometry_compressor.GetPositionForID(e1), + component_id, i, forward_data.travel_mode, reverse_data.travel_mode); current_edge_source_coordinate_id = current_edge_target_coordinate_id; BOOST_ASSERT(m_edge_based_node_list.back().IsCompressed()); @@ -224,20 +216,10 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, BOOST_ASSERT(forward_data.edgeBasedNodeID != SPECIAL_NODEID || reverse_data.edgeBasedNodeID != SPECIAL_NODEID); - m_edge_based_node_list.emplace_back(forward_data.edgeBasedNodeID, - reverse_data.edgeBasedNodeID, - node_u, - node_v, - forward_data.nameID, - forward_data.distance, - reverse_data.distance, - 0, - 0, - SPECIAL_EDGEID, - component_id, - 0, - forward_data.travel_mode, - reverse_data.travel_mode); + m_edge_based_node_list.emplace_back( + forward_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID, node_u, node_v, + forward_data.nameID, forward_data.distance, reverse_data.distance, 0, 0, SPECIAL_EDGEID, + component_id, 0, forward_data.travel_mode, reverse_data.travel_mode); BOOST_ASSERT(!m_edge_based_node_list.back().IsCompressed()); } } @@ -245,7 +227,8 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, void EdgeBasedGraphFactory::FlushVectorToStream( std::ofstream &edge_data_file, std::vector &original_edge_data_vector) const { - if (original_edge_data_vector.empty()) { + if (original_edge_data_vector.empty()) + { return; } edge_data_file.write((char *)&(original_edge_data_vector[0]), @@ -342,15 +325,15 @@ void EdgeBasedGraphFactory::CompressGeometry() 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(node_u, node_w) != m_node_based_graph->EndEdges(node_u)) || + if ((m_node_based_graph->FindEdge(node_u, node_w) != + m_node_based_graph->EndEdges(node_u)) || (m_node_based_graph->FindEdge(node_w, node_u) != m_node_based_graph->EndEdges(node_w))) { continue; } if ( // TODO: rename to IsCompatibleTo - fwd_edge_data1.IsEqualTo(fwd_edge_data2) && - rev_edge_data1.IsEqualTo(rev_edge_data2)) + fwd_edge_data1.IsEqualTo(fwd_edge_data2) && rev_edge_data1.IsEqualTo(rev_edge_data2)) { // Get distances before graph is modified const int forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; @@ -389,30 +372,21 @@ void EdgeBasedGraphFactory::CompressGeometry() // update any involved turn restrictions m_restriction_map->FixupStartingTurnRestriction(node_u, node_v, node_w); - m_restriction_map->FixupArrivingTurnRestriction(node_u, node_v, - node_w, + m_restriction_map->FixupArrivingTurnRestriction(node_u, node_v, node_w, m_node_based_graph); m_restriction_map->FixupStartingTurnRestriction(node_w, node_v, node_u); - m_restriction_map->FixupArrivingTurnRestriction(node_w, - node_v, - node_u, m_node_based_graph); + m_restriction_map->FixupArrivingTurnRestriction(node_w, node_v, node_u, + m_node_based_graph); // store compressed geometry in container m_geometry_compressor.CompressEdge( - forward_e1, - forward_e2, - node_v, - node_w, + forward_e1, forward_e2, node_v, node_w, forward_weight1 + (add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0), forward_weight2); m_geometry_compressor.CompressEdge( - reverse_e1, - reverse_e2, - node_v, - node_u, - reverse_weight1, + reverse_e1, reverse_e2, node_v, node_u, reverse_weight1, reverse_weight2 + (add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0)); ++removed_node_count; @@ -427,7 +401,7 @@ void EdgeBasedGraphFactory::CompressGeometry() unsigned new_node_count = 0; unsigned new_edge_count = 0; - for(const auto i : osrm::irange(0u, m_node_based_graph->GetNumberOfNodes())) + for (const auto i : osrm::irange(0u, m_node_based_graph->GetNumberOfNodes())) { if (m_node_based_graph->GetOutDegree(i) > 0) { @@ -436,10 +410,10 @@ void EdgeBasedGraphFactory::CompressGeometry() } } 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; + 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; } /** @@ -477,14 +451,16 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() SimpleLogger().Write() << "Identifying components of the (compressed) road network"; // Run a BFS on the undirected graph and identify small components - TarjanSCC component_explorer( - m_node_based_graph, *m_restriction_map, m_barrier_nodes); + TarjanSCC component_explorer(m_node_based_graph, *m_restriction_map, + m_barrier_nodes); component_explorer.run(); - SimpleLogger().Write() << "identified: " << component_explorer.get_number_of_components() - removed_node_count + SimpleLogger().Write() << "identified: " + << component_explorer.get_number_of_components() - removed_node_count << " (compressed) components"; - SimpleLogger().Write() << "identified " << component_explorer.get_size_one_count() - removed_node_count + SimpleLogger().Write() << "identified " + << component_explorer.get_size_one_count() - removed_node_count << " (compressed) SCCs of size 1"; SimpleLogger().Write() << "generating edge-expanded nodes"; @@ -516,8 +492,10 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() const unsigned size_of_component = std::min(component_explorer.get_component_size(u), component_explorer.get_component_size(v)); - const unsigned id_of_smaller_component = [u,v,&component_explorer] { - if (component_explorer.get_component_size(u) < component_explorer.get_component_size(v)) + const unsigned id_of_smaller_component = [u, v, &component_explorer] + { + if (component_explorer.get_component_size(u) < + component_explorer.get_component_size(v)) { return component_explorer.get_component_id(u); } @@ -544,9 +522,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() /** * Actually it also generates OriginalEdgeData and serializes them... */ -void -EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edge_data_filename, - lua_State *lua_state) +void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( + const std::string &original_edge_data_filename, lua_State *lua_state) { SimpleLogger().Write() << "generating edge-expanded edges"; @@ -647,14 +624,16 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg } // unpack last node of first segment if packed - const auto first_coordinate = m_node_info_list[(m_geometry_compressor.HasEntryForID(e1) ? - m_geometry_compressor.GetLastNodeIDOfBucket(e1) : - u)]; + const auto first_coordinate = + m_node_info_list[(m_geometry_compressor.HasEntryForID(e1) + ? m_geometry_compressor.GetLastNodeIDOfBucket(e1) + : u)]; // unpack first node of second segment if packed - const auto third_coordinate = m_node_info_list[(m_geometry_compressor.HasEntryForID(e2) ? - m_geometry_compressor.GetFirstNodeIDOfBucket(e2) : - w)]; + const auto third_coordinate = + m_node_info_list[(m_geometry_compressor.HasEntryForID(e2) + ? m_geometry_compressor.GetFirstNodeIDOfBucket(e2) + : w)]; const double turn_angle = ComputeAngle::OfThreeFixedPointCoordinates( first_coordinate, m_node_info_list[v], third_coordinate); @@ -676,9 +655,7 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg original_edge_data_vector.emplace_back( (edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v), - edge_data1.nameID, - turn_instruction, - edge_is_compressed, + edge_data1.nameID, turn_instruction, edge_is_compressed, edge_data2.travel_mode); ++original_edges_counter; @@ -691,12 +668,9 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg BOOST_ASSERT(SPECIAL_NODEID != edge_data1.edgeBasedNodeID); BOOST_ASSERT(SPECIAL_NODEID != edge_data2.edgeBasedNodeID); - m_edge_based_edge_list.emplace_back(EdgeBasedEdge(edge_data1.edgeBasedNodeID, - edge_data2.edgeBasedNodeID, - m_edge_based_edge_list.size(), - distance, - true, - false)); + m_edge_based_edge_list.emplace_back( + EdgeBasedEdge(edge_data1.edgeBasedNodeID, edge_data2.edgeBasedNodeID, + m_edge_based_edge_list.size(), distance, true, false)); } } } @@ -727,7 +701,10 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co // call lua profile to compute turn penalty return luabind::call_function(lua_state, "turn_function", 180. - angle); } - catch (const luabind::error &er) { SimpleLogger().Write(logWARNING) << er.what(); } + catch (const luabind::error &er) + { + SimpleLogger().Write(logWARNING) << er.what(); + } } return 0; } @@ -735,8 +712,7 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID node_u, const NodeID node_v, const NodeID node_w, - const double angle) - const + const double angle) const { if (node_u == node_w) { diff --git a/contractor/processing_chain.cpp b/contractor/processing_chain.cpp index 23d406b2e..46c12d0dd 100644 --- a/contractor/processing_chain.cpp +++ b/contractor/processing_chain.cpp @@ -138,13 +138,9 @@ int Prepare::Process(int argc, char *argv[]) static_assert(sizeof(ImportEdge) == 20, "changing ImportEdge type has influence on memory consumption!"); #endif - NodeID number_of_node_based_nodes = - readBinaryOSRMGraphFromStream(input_stream, - edge_list, - barrier_node_list, - traffic_light_list, - &internal_to_external_node_map, - restriction_list); + NodeID number_of_node_based_nodes = readBinaryOSRMGraphFromStream( + input_stream, edge_list, barrier_node_list, traffic_light_list, + &internal_to_external_node_map, restriction_list); input_stream.close(); if (edge_list.empty()) @@ -162,11 +158,9 @@ int Prepare::Process(int argc, char *argv[]) DeallocatingVector edge_based_edge_list; // init node_based_edge_list, edge_based_edge_list by edgeList - number_of_edge_based_nodes = BuildEdgeExpandedGraph(lua_state, - number_of_node_based_nodes, - node_based_edge_list, - edge_based_edge_list, - speed_profile); + number_of_edge_based_nodes = + BuildEdgeExpandedGraph(lua_state, number_of_node_based_nodes, node_based_edge_list, + edge_based_edge_list, speed_profile); lua_close(lua_state); TIMER_STOP(expansion); @@ -343,9 +337,8 @@ bool Prepare::ParseArguments(int argc, char *argv[]) // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( - "config,c", - boost::program_options::value(&config_file_path) - ->default_value("contractor.ini"), + "config,c", boost::program_options::value(&config_file_path) + ->default_value("contractor.ini"), "Path to a configuration file."); // declare a group of options that will be allowed both on command line and in config file @@ -354,21 +347,18 @@ bool Prepare::ParseArguments(int argc, char *argv[]) "restrictions,r", boost::program_options::value(&restrictions_path), "Restrictions file in .osrm.restrictions format")( - "profile,p", - boost::program_options::value(&profile_path) - ->default_value("profile.lua"), + "profile,p", boost::program_options::value(&profile_path) + ->default_value("profile.lua"), "Path to LUA routing profile")( - "threads,t", - boost::program_options::value(&requested_num_threads) - ->default_value(tbb::task_scheduler_init::default_num_threads()), + "threads,t", boost::program_options::value(&requested_num_threads) + ->default_value(tbb::task_scheduler_init::default_num_threads()), "Number of threads to use"); // hidden options, will be allowed both on command line and in config file, but will not be // shown to the user boost::program_options::options_description hidden_options("Hidden options"); hidden_options.add_options()( - "input,i", - boost::program_options::value(&input_path), + "input,i", boost::program_options::value(&input_path), "Input file in .osm, .osm.bz2 or .osm.pbf format"); // positional option @@ -394,10 +384,11 @@ bool Prepare::ParseArguments(int argc, char *argv[]) .run(), option_variables); - const auto& temp_config_path = option_variables["config"].as(); + const auto &temp_config_path = option_variables["config"].as(); if (boost::filesystem::is_regular_file(temp_config_path)) { - boost::program_options::store(boost::program_options::parse_config_file(temp_config_path.string().c_str(), cmdline_options, true), + boost::program_options::store(boost::program_options::parse_config_file( + temp_config_path.string().c_str(), cmdline_options, true), option_variables); } @@ -458,9 +449,8 @@ void Prepare::CheckRestrictionsFile(FingerPrint &fingerprint_orig) \brief Setups scripting environment (lua-scripting) Also initializes speed profile. */ -bool -Prepare::SetupScriptingEnvironment(lua_State *lua_state, - EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile) +bool Prepare::SetupScriptingEnvironment( + lua_State *lua_state, EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile) { // open utility libraries string library; luaL_openlibs(lua_state); @@ -509,14 +499,12 @@ Prepare::BuildEdgeExpandedGraph(lua_State *lua_state, SimpleLogger().Write() << "Generating edge-expanded graph representation"; std::shared_ptr node_based_graph = NodeBasedDynamicGraphFromImportEdges(number_of_node_based_nodes, edge_list); - std::unique_ptr restriction_map = osrm::make_unique(restriction_list); + std::unique_ptr restriction_map = + osrm::make_unique(restriction_list); std::shared_ptr edge_based_graph_factory = - std::make_shared(node_based_graph, - std::move(restriction_map), - barrier_node_list, - traffic_light_list, - internal_to_external_node_map, - speed_profile); + std::make_shared(node_based_graph, std::move(restriction_map), + barrier_node_list, traffic_light_list, + internal_to_external_node_map, speed_profile); edge_list.clear(); edge_list.shrink_to_fit(); @@ -574,8 +562,6 @@ void Prepare::WriteNodeMapping() void Prepare::BuildRTree(std::vector &node_based_edge_list) { SimpleLogger().Write() << "building r-tree ..."; - StaticRTree(node_based_edge_list, - rtree_nodes_path.c_str(), - rtree_leafs_path.c_str(), - internal_to_external_node_map); + StaticRTree(node_based_edge_list, rtree_nodes_path.c_str(), + rtree_leafs_path.c_str(), internal_to_external_node_map); } diff --git a/data_structures/coordinate.cpp b/data_structures/coordinate.cpp index dbddc4742..de0b696f0 100644 --- a/data_structures/coordinate.cpp +++ b/data_structures/coordinate.cpp @@ -93,8 +93,8 @@ void FixedPointCoordinate::Output(std::ostream &out) const float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &other) const { - const float lon_delta = - coordinate_calculation::deg_to_rad(lon / COORDINATE_PRECISION - other.lon / COORDINATE_PRECISION); + const float lon_delta = coordinate_calculation::deg_to_rad(lon / COORDINATE_PRECISION - + other.lon / COORDINATE_PRECISION); const float lat1 = coordinate_calculation::deg_to_rad(other.lat / COORDINATE_PRECISION); const float lat2 = coordinate_calculation::deg_to_rad(lat / COORDINATE_PRECISION); const float y_value = std::sin(lon_delta) * std::cos(lat2); diff --git a/data_structures/coordinate_calculation.cpp b/data_structures/coordinate_calculation.cpp index cc0474c79..3ea5ae96d 100644 --- a/data_structures/coordinate_calculation.cpp +++ b/data_structures/coordinate_calculation.cpp @@ -36,7 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -namespace +namespace { constexpr static const float RAD = 0.017453292519943295769236907684886; constexpr static const float earth_radius = 6372797.560856f; @@ -72,23 +72,23 @@ double coordinate_calculation::ApproximateDistance(const int lat1, } double coordinate_calculation::ApproximateDistance(const FixedPointCoordinate &coordinate_1, - const FixedPointCoordinate &coordinate_2) + const FixedPointCoordinate &coordinate_2) { - return ApproximateDistance( - coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); + return ApproximateDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, + coordinate_2.lon); } float coordinate_calculation::approx_euclidean_distance(const FixedPointCoordinate &coordinate_1, - const FixedPointCoordinate &coordinate_2) + const FixedPointCoordinate &coordinate_2) { - return approx_euclidean_distance( - coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); + return approx_euclidean_distance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, + coordinate_2.lon); } float coordinate_calculation::approx_euclidean_distance(const int lat1, - const int lon1, - const int lat2, - const int lon2) + const int lon1, + const int lat2, + const int lon2) { BOOST_ASSERT(lat1 != std::numeric_limits::min()); BOOST_ASSERT(lon1 != std::numeric_limits::min()); @@ -105,26 +105,24 @@ float coordinate_calculation::approx_euclidean_distance(const int lat1, return sqrt(x_value * x_value + y_value * y_value) * earth_radius; } -float -coordinate_calculation::ComputePerpendicularDistance(const FixedPointCoordinate &source_coordinate, - const FixedPointCoordinate &target_coordinate, - const FixedPointCoordinate &query_location) +float coordinate_calculation::ComputePerpendicularDistance( + const FixedPointCoordinate &source_coordinate, + const FixedPointCoordinate &target_coordinate, + const FixedPointCoordinate &query_location) { float ratio; FixedPointCoordinate nearest_location; - return ComputePerpendicularDistance(source_coordinate, - target_coordinate, - query_location, - nearest_location, - ratio); + return ComputePerpendicularDistance(source_coordinate, target_coordinate, query_location, + nearest_location, ratio); } -float coordinate_calculation::ComputePerpendicularDistance(const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, - FixedPointCoordinate &nearest_location, - float &ratio) +float coordinate_calculation::ComputePerpendicularDistance( + const FixedPointCoordinate &segment_source, + const FixedPointCoordinate &segment_target, + const FixedPointCoordinate &query_location, + FixedPointCoordinate &nearest_location, + float &ratio) { BOOST_ASSERT(query_location.is_valid()); @@ -197,31 +195,27 @@ float coordinate_calculation::ComputePerpendicularDistance(const FixedPointCoord return approximate_distance; } -float -coordinate_calculation::perpendicular_distance_from_projected_coordinate( - const FixedPointCoordinate &source_coordinate, - const FixedPointCoordinate &target_coordinate, - const FixedPointCoordinate &query_location, - const std::pair &projected_coordinate) +float coordinate_calculation::perpendicular_distance_from_projected_coordinate( + const FixedPointCoordinate &source_coordinate, + const FixedPointCoordinate &target_coordinate, + const FixedPointCoordinate &query_location, + const std::pair &projected_coordinate) { float ratio; FixedPointCoordinate nearest_location; - return perpendicular_distance_from_projected_coordinate(source_coordinate, - target_coordinate, - query_location, - projected_coordinate, - nearest_location, - ratio); + return perpendicular_distance_from_projected_coordinate(source_coordinate, target_coordinate, + query_location, projected_coordinate, + nearest_location, ratio); } float coordinate_calculation::perpendicular_distance_from_projected_coordinate( - const FixedPointCoordinate &segment_source, - const FixedPointCoordinate &segment_target, - const FixedPointCoordinate &query_location, - const std::pair &projected_coordinate, - FixedPointCoordinate &nearest_location, - float &ratio) + const FixedPointCoordinate &segment_source, + const FixedPointCoordinate &segment_target, + const FixedPointCoordinate &query_location, + const std::pair &projected_coordinate, + FixedPointCoordinate &nearest_location, + float &ratio) { BOOST_ASSERT(query_location.is_valid()); @@ -302,7 +296,7 @@ void coordinate_calculation::lat_or_lon_to_string(const int value, std::string & } void coordinate_calculation::convertInternalCoordinateToString(const FixedPointCoordinate &coord, - std::string &output) + std::string &output) { std::string tmp; tmp.reserve(23); @@ -313,9 +307,8 @@ void coordinate_calculation::convertInternalCoordinateToString(const FixedPointC output += tmp; } -void -coordinate_calculation::convertInternalReversedCoordinateToString(const FixedPointCoordinate &coord, - std::string &output) +void coordinate_calculation::convertInternalReversedCoordinateToString( + const FixedPointCoordinate &coord, std::string &output) { std::string tmp; tmp.reserve(23); @@ -327,7 +320,7 @@ coordinate_calculation::convertInternalReversedCoordinateToString(const FixedPoi } float coordinate_calculation::GetBearing(const FixedPointCoordinate &first_coordinate, - const FixedPointCoordinate &second_coordinate) + const FixedPointCoordinate &second_coordinate) { const float lon_diff = second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION; diff --git a/datastore.cpp b/datastore.cpp index 011fa09b6..14bde95bd 100644 --- a/datastore.cpp +++ b/datastore.cpp @@ -103,7 +103,8 @@ int main(const int argc, const char *argv[]) const bool lock_flags = MCL_CURRENT | MCL_FUTURE; if (-1 == mlockall(lock_flags)) { - SimpleLogger().Write(logWARNING) << "Process " << argv[0] << " could not request RAM lock"; + SimpleLogger().Write(logWARNING) << "Process " << argv[0] + << " could not request RAM lock"; } #endif try @@ -340,8 +341,8 @@ int main(const int argc, const char *argv[]) geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned)); shared_layout_ptr->SetBlockSize(SharedDataLayout::GEOMETRIES_INDEX, number_of_geometries_indices); - boost::iostreams::seek( - geometry_input_stream, number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur); + 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->SetBlockSize(SharedDataLayout::GEOMETRIES_LIST, number_of_compressed_geometries); @@ -410,9 +411,8 @@ int main(const int argc, const char *argv[]) unsigned *name_id_ptr = shared_layout_ptr->GetBlockPtr( shared_memory_ptr, SharedDataLayout::NAME_ID_LIST); - TravelMode *travel_mode_ptr = - shared_layout_ptr->GetBlockPtr( - shared_memory_ptr, SharedDataLayout::TRAVEL_MODE); + TravelMode *travel_mode_ptr = shared_layout_ptr->GetBlockPtr( + shared_memory_ptr, SharedDataLayout::TRAVEL_MODE); TurnInstruction *turn_instructions_ptr = shared_layout_ptr->GetBlockPtr( diff --git a/extractor/extraction_containers.cpp b/extractor/extraction_containers.cpp index 682fb1652..4675db2d2 100644 --- a/extractor/extraction_containers.cpp +++ b/extractor/extraction_containers.cpp @@ -83,32 +83,25 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, TIMER_STOP(erasing_dups); std::cout << "ok, after " << TIMER_SEC(erasing_dups) << "s" << std::endl; - std::cout << "[extractor] Sorting all nodes ... " << std::flush; TIMER_START(sorting_nodes); - stxxl::sort(all_nodes_list.begin(), - all_nodes_list.end(), - ExternalMemoryNodeSTXXLCompare(), + stxxl::sort(all_nodes_list.begin(), all_nodes_list.end(), ExternalMemoryNodeSTXXLCompare(), stxxl_memory); TIMER_STOP(sorting_nodes); std::cout << "ok, after " << TIMER_SEC(sorting_nodes) << "s" << std::endl; - std::cout << "[extractor] Sorting used ways ... " << std::flush; TIMER_START(sort_ways); - stxxl::sort(way_start_end_id_list.begin(), - way_start_end_id_list.end(), - FirstAndLastSegmentOfWayStxxlCompare(), - stxxl_memory); + stxxl::sort(way_start_end_id_list.begin(), way_start_end_id_list.end(), + FirstAndLastSegmentOfWayStxxlCompare(), stxxl_memory); TIMER_STOP(sort_ways); std::cout << "ok, after " << TIMER_SEC(sort_ways) << "s" << std::endl; - std::cout << "[extractor] Sorting " << restrictions_list.size() << " restrictions. by from... " << std::flush; + std::cout << "[extractor] Sorting " << restrictions_list.size() + << " restrictions. by from... " << std::flush; TIMER_START(sort_restrictions); - stxxl::sort(restrictions_list.begin(), - restrictions_list.end(), - CmpRestrictionContainerByFrom(), - stxxl_memory); + stxxl::sort(restrictions_list.begin(), restrictions_list.end(), + CmpRestrictionContainerByFrom(), stxxl_memory); TIMER_STOP(sort_restrictions); std::cout << "ok, after " << TIMER_SEC(sort_restrictions) << "s" << std::endl; @@ -132,7 +125,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, continue; } - BOOST_ASSERT(way_start_and_end_iterator->way_id == restrictions_iterator->restriction.from.way); + BOOST_ASSERT(way_start_and_end_iterator->way_id == + restrictions_iterator->restriction.from.way); const NodeID via_node_id = restrictions_iterator->restriction.via.node; if (way_start_and_end_iterator->first_segment_source_id == via_node_id) @@ -153,10 +147,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, std::cout << "[extractor] Sorting restrictions. by to ... " << std::flush; TIMER_START(sort_restrictions_to); - stxxl::sort(restrictions_list.begin(), - restrictions_list.end(), - CmpRestrictionContainerByTo(), - stxxl_memory); + stxxl::sort(restrictions_list.begin(), restrictions_list.end(), + CmpRestrictionContainerByTo(), stxxl_memory); TIMER_STOP(sort_restrictions_to); std::cout << "ok, after " << TIMER_SEC(sort_restrictions_to) << "s" << std::endl; @@ -177,7 +169,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, ++restrictions_iterator; continue; } - BOOST_ASSERT(way_start_and_end_iterator->way_id == restrictions_iterator->restriction.to.way); + BOOST_ASSERT(way_start_and_end_iterator->way_id == + restrictions_iterator->restriction.to.way); const NodeID via_node_id = restrictions_iterator->restriction.via.node; if (way_start_and_end_iterator->first_segment_source_id == via_node_id) @@ -203,7 +196,7 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, const auto count_position = restrictions_out_stream.tellp(); restrictions_out_stream.write((char *)&written_restriction_count, sizeof(unsigned)); - for(const auto & restriction_container : restrictions_list) + for (const auto &restriction_container : restrictions_list) { if (SPECIAL_NODEID != restriction_container.restriction.from.node && SPECIAL_NODEID != restriction_container.restriction.to.node) @@ -267,7 +260,6 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, TIMER_STOP(sort_edges_by_start); std::cout << "ok, after " << TIMER_SEC(sort_edges_by_start) << "s" << std::endl; - std::cout << "[extractor] Setting start coords ... " << std::flush; TIMER_START(set_start_coords); file_out_stream.write((char *)&number_of_used_edges, sizeof(unsigned)); @@ -298,7 +290,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, // Sort Edges by target std::cout << "[extractor] Sorting edges by target ... " << std::flush; TIMER_START(sort_edges_by_target); - stxxl::sort(all_edges_list.begin(), all_edges_list.end(), CmpEdgeByTargetID(), stxxl_memory); + stxxl::sort(all_edges_list.begin(), all_edges_list.end(), CmpEdgeByTargetID(), + stxxl_memory); TIMER_STOP(sort_edges_by_target); std::cout << "ok, after " << TIMER_SEC(sort_edges_by_target) << "s" << std::endl; @@ -329,16 +322,13 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, edge_iterator->target_coordinate.lon = node_iterator->lon; const double distance = coordinate_calculation::approx_euclidean_distance( - edge_iterator->source_coordinate.lat, - edge_iterator->source_coordinate.lon, - node_iterator->lat, - node_iterator->lon); + edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon, + node_iterator->lat, node_iterator->lon); const double weight = (distance * 10.) / (edge_iterator->speed / 3.6); int integer_weight = std::max( - 1, - (int)std::floor( - (edge_iterator->is_duration_set ? edge_iterator->speed : weight) + .5)); + 1, (int)std::floor( + (edge_iterator->is_duration_set ? edge_iterator->speed : weight) + .5)); const int integer_distance = std::max(1, (int)distance); const short zero = 0; const short one = 1; @@ -371,30 +361,38 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, if (edge_iterator->is_roundabout) { file_out_stream.write((char *)&yes, sizeof(bool)); - } else { + } + else + { file_out_stream.write((char *)&no, sizeof(bool)); } if (edge_iterator->is_in_tiny_cc) { file_out_stream.write((char *)&yes, sizeof(bool)); - } else { + } + else + { file_out_stream.write((char *)&no, sizeof(bool)); } if (edge_iterator->is_access_restricted) { file_out_stream.write((char *)&yes, sizeof(bool)); - } else { + } + else + { file_out_stream.write((char *)&no, sizeof(bool)); } // cannot take adress of bit field, so use local - const TravelMode travel_mode = edge_iterator->travel_mode; + const TravelMode travel_mode = edge_iterator->travel_mode; file_out_stream.write((char *)&travel_mode, sizeof(TravelMode)); if (edge_iterator->is_split) { file_out_stream.write((char *)&yes, sizeof(bool)); - } else { + } + else + { file_out_stream.write((char *)&no, sizeof(bool)); } ++number_of_used_edges; @@ -420,7 +418,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, std::vector name_lengths; for (const std::string &temp_string : name_list) { - const unsigned string_length = std::min(static_cast(temp_string.length()), 255u); + const unsigned string_length = + std::min(static_cast(temp_string.length()), 255u); name_lengths.push_back(string_length); total_length += string_length; } @@ -428,11 +427,12 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, RangeTable<> table(name_lengths); name_file_stream << table; - name_file_stream.write((char*) &total_length, sizeof(unsigned)); + name_file_stream.write((char *)&total_length, sizeof(unsigned)); // write all chars consecutively for (const std::string &temp_string : name_list) { - const unsigned string_length = std::min(static_cast(temp_string.length()), 255u); + const unsigned string_length = + std::min(static_cast(temp_string.length()), 255u); name_file_stream.write(temp_string.c_str(), string_length); } @@ -443,5 +443,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name, SimpleLogger().Write() << "Processed " << number_of_used_nodes << " nodes and " << number_of_used_edges << " edges"; } - catch (const std::exception &e) { std::cerr << "Caught Execption:" << e.what() << std::endl; } + catch (const std::exception &e) + { + std::cerr << "Caught Execption:" << e.what() << std::endl; + } } diff --git a/extractor/extraction_containers.hpp b/extractor/extraction_containers.hpp index 68df14cff..588dcabb0 100644 --- a/extractor/extraction_containers.hpp +++ b/extractor/extraction_containers.hpp @@ -39,17 +39,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class ExtractionContainers { #ifndef _MSC_VER - constexpr static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? std::numeric_limits::max() : std::numeric_limits::max()); + constexpr static unsigned stxxl_memory = + ((sizeof(std::size_t) == 4) ? std::numeric_limits::max() + : std::numeric_limits::max()); #else const static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? INT_MAX : UINT_MAX); #endif public: - using STXXLNodeIDVector = stxxl::vector; - using STXXLNodeVector = stxxl::vector; - using STXXLEdgeVector = stxxl::vector; - using STXXLStringVector = stxxl::vector; - using STXXLRestrictionsVector = stxxl::vector; - using STXXLWayIDStartEndVector = stxxl::vector; + using STXXLNodeIDVector = stxxl::vector; + using STXXLNodeVector = stxxl::vector; + using STXXLEdgeVector = stxxl::vector; + using STXXLStringVector = stxxl::vector; + using STXXLRestrictionsVector = stxxl::vector; + using STXXLWayIDStartEndVector = stxxl::vector; STXXLNodeIDVector used_node_id_list; STXXLNodeVector all_nodes_list; diff --git a/extractor/extraction_node.hpp b/extractor/extraction_node.hpp index defd33394..7fd7d7ca9 100644 --- a/extractor/extraction_node.hpp +++ b/extractor/extraction_node.hpp @@ -30,11 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct ExtractionNode { - ExtractionNode() : traffic_lights(false), barrier(false) { } - void clear() - { - traffic_lights = barrier = false; - } + ExtractionNode() : traffic_lights(false), barrier(false) {} + void clear() { traffic_lights = barrier = false; } bool traffic_lights; bool barrier; }; diff --git a/extractor/extraction_way.hpp b/extractor/extraction_way.hpp index b41448758..97133b3af 100644 --- a/extractor/extraction_way.hpp +++ b/extractor/extraction_way.hpp @@ -52,10 +52,12 @@ struct ExtractionWay } enum Directions - { notSure = 0, - oneway, - bidirectional, - opposite }; + { + notSure = 0, + oneway, + bidirectional, + opposite + }; // These accessor methods exists to support the depreciated "way.direction" access // in LUA. Since the direction attribute was removed from ExtractionWay, the @@ -69,19 +71,20 @@ struct ExtractionWay } else if (Directions::opposite == m) { - forward_travel_mode = TRAVEL_MODE_INACCESSIBLE; - backward_travel_mode = TRAVEL_MODE_DEFAULT; + forward_travel_mode = TRAVEL_MODE_INACCESSIBLE; + backward_travel_mode = TRAVEL_MODE_DEFAULT; } else if (Directions::bidirectional == m) { - forward_travel_mode = TRAVEL_MODE_DEFAULT; - backward_travel_mode = TRAVEL_MODE_DEFAULT; + forward_travel_mode = TRAVEL_MODE_DEFAULT; + backward_travel_mode = TRAVEL_MODE_DEFAULT; } } Directions get_direction() const { - if (TRAVEL_MODE_INACCESSIBLE != forward_travel_mode && TRAVEL_MODE_INACCESSIBLE != backward_travel_mode) + if (TRAVEL_MODE_INACCESSIBLE != forward_travel_mode && + TRAVEL_MODE_INACCESSIBLE != backward_travel_mode) { return Directions::bidirectional; } diff --git a/extractor/extractor.cpp b/extractor/extractor.cpp index d8a3d5563..136789e14 100644 --- a/extractor/extractor.cpp +++ b/extractor/extractor.cpp @@ -99,7 +99,8 @@ int Extractor::Run(int argc, char *argv[]) } const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads(); - const auto number_of_threads = std::min(recommended_num_threads, extractor_config.requested_num_threads); + const auto number_of_threads = + std::min(recommended_num_threads, extractor_config.requested_num_threads); tbb::task_scheduler_init init(number_of_threads); SimpleLogger().Write() << "Input file: " << extractor_config.input_path.filename().string(); @@ -120,10 +121,10 @@ int Extractor::Run(int argc, char *argv[]) osmium::io::Reader reader(input_file); const osmium::io::Header header = reader.header(); - std::atomic number_of_nodes {0}; - std::atomic number_of_ways {0}; - std::atomic number_of_relations {0}; - std::atomic number_of_others {0}; + std::atomic number_of_nodes{0}; + std::atomic number_of_ways{0}; + std::atomic number_of_relations{0}; + std::atomic number_of_others{0}; SimpleLogger().Write() << "Parsing in progress.."; TIMER_START(parsing); @@ -160,7 +161,8 @@ int Extractor::Run(int argc, char *argv[]) { // create a vector of iterators into the buffer std::vector osm_elements; - for (auto iter = std::begin(buffer); iter != std::end(buffer); ++iter) { + for (auto iter = std::begin(buffer); iter != std::end(buffer); ++iter) + { osm_elements.push_back(iter); } @@ -170,56 +172,56 @@ int Extractor::Run(int argc, char *argv[]) resulting_restrictions.clear(); // parse OSM entities in parallel, store in resulting vectors - tbb::parallel_for(tbb::blocked_range(0, osm_elements.size()), - [&](const tbb::blocked_range &range) - { - ExtractionNode result_node; - ExtractionWay result_way; - lua_State * local_state = scripting_environment.get_lua_state(); - - for (auto x = range.begin(); x != range.end(); ++x) + tbb::parallel_for( + tbb::blocked_range(0, osm_elements.size()), + [&](const tbb::blocked_range &range) { - const auto entity = osm_elements[x]; + ExtractionNode result_node; + ExtractionWay result_way; + lua_State *local_state = scripting_environment.get_lua_state(); - switch (entity->type()) + for (auto x = range.begin(); x != range.end(); ++x) { - case osmium::item_type::node: - result_node.clear(); - ++number_of_nodes; - luabind::call_function( - local_state, - "node_function", - boost::cref(static_cast(*entity)), - boost::ref(result_node)); - resulting_nodes.push_back(std::make_pair(x, result_node)); - break; - case osmium::item_type::way: - result_way.clear(); - ++number_of_ways; - luabind::call_function( - local_state, - "way_function", - boost::cref(static_cast(*entity)), - boost::ref(result_way)); - resulting_ways.push_back(std::make_pair(x, result_way)); - break; - case osmium::item_type::relation: - ++number_of_relations; - resulting_restrictions.push_back( - restriction_parser.TryParse(static_cast(*entity))); - break; - default: - ++number_of_others; - break; + const auto entity = osm_elements[x]; + + switch (entity->type()) + { + case osmium::item_type::node: + result_node.clear(); + ++number_of_nodes; + luabind::call_function( + local_state, "node_function", + boost::cref(static_cast(*entity)), + boost::ref(result_node)); + resulting_nodes.push_back(std::make_pair(x, result_node)); + break; + case osmium::item_type::way: + result_way.clear(); + ++number_of_ways; + luabind::call_function( + local_state, "way_function", + boost::cref(static_cast(*entity)), + boost::ref(result_way)); + resulting_ways.push_back(std::make_pair(x, result_way)); + break; + case osmium::item_type::relation: + ++number_of_relations; + resulting_restrictions.push_back(restriction_parser.TryParse( + static_cast(*entity))); + break; + default: + ++number_of_others; + break; + } } - } - }); + }); // put parsed objects thru extractor callbacks for (const auto &result : resulting_nodes) { extractor_callbacks->ProcessNode( - static_cast(*(osm_elements[result.first])), result.second); + static_cast(*(osm_elements[result.first])), + result.second); } for (const auto &result : resulting_ways) { @@ -238,11 +240,8 @@ int Extractor::Run(int argc, char *argv[]) unsigned nw = number_of_ways; unsigned nr = number_of_relations; unsigned no = number_of_others; - SimpleLogger().Write() << "Raw input contains " - << nn << " nodes, " - << nw << " ways, and " - << nr << " relations, and " - << no << " unknown entities"; + SimpleLogger().Write() << "Raw input contains " << nn << " nodes, " << nw << " ways, and " + << nr << " relations, and " << no << " unknown entities"; extractor_callbacks.reset(); diff --git a/extractor/extractor_callbacks.cpp b/extractor/extractor_callbacks.cpp index 7ab0fc409..361c7e5ce 100644 --- a/extractor/extractor_callbacks.cpp +++ b/extractor/extractor_callbacks.cpp @@ -51,13 +51,12 @@ ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containe void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node, const ExtractionNode &result_node) { - external_memory.all_nodes_list.push_back({ - static_cast(input_node.location().lat() * COORDINATE_PRECISION), - static_cast(input_node.location().lon() * COORDINATE_PRECISION), - static_cast(input_node.id()), - result_node.barrier, - result_node.traffic_lights - }); + external_memory.all_nodes_list.push_back( + {static_cast(input_node.location().lat() * COORDINATE_PRECISION), + static_cast(input_node.location().lon() * COORDINATE_PRECISION), + static_cast(input_node.id()), + result_node.barrier, + result_node.traffic_lights}); } void ExtractorCallbacks::ProcessRestriction( @@ -69,7 +68,8 @@ void ExtractorCallbacks::ProcessRestriction( // SimpleLogger().Write() << "from: " << restriction.get().restriction.from.node << // ",via: " << restriction.get().restriction.via.node << // ", to: " << restriction.get().restriction.to.node << - // ", only: " << (restriction.get().restriction.flags.is_only ? "y" : "n"); + // ", only: " << (restriction.get().restriction.flags.is_only ? + // "y" : "n"); } } /** warning: caller needs to take care of synchronization! */ @@ -99,8 +99,10 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti { // TODO: iterate all way segments and set duration corresponding to the length of each // segment - const_cast(parsed_way).forward_speed = parsed_way.duration / (input_way.nodes().size() - 1); - const_cast(parsed_way).backward_speed = parsed_way.duration / (input_way.nodes().size() - 1); + const_cast(parsed_way).forward_speed = + parsed_way.duration / (input_way.nodes().size() - 1); + const_cast(parsed_way).backward_speed = + parsed_way.duration / (input_way.nodes().size() - 1); } if (std::numeric_limits::epsilon() >= std::abs(-1. - parsed_way.forward_speed)) @@ -129,41 +131,36 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti ((parsed_way.forward_speed != parsed_way.backward_speed) || (parsed_way.forward_travel_mode != parsed_way.backward_travel_mode)); - auto pair_wise_segment_split = [&](const osmium::NodeRef &first_node, - const osmium::NodeRef &last_node) + auto pair_wise_segment_split = + [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) { // SimpleLogger().Write() << "adding edge (" << first_node.ref() << "," << // last_node.ref() << "), fwd speed: " << parsed_way.forward_speed; external_memory.all_edges_list.push_back(InternalExtractorEdge( - first_node.ref(), - last_node.ref(), + first_node.ref(), last_node.ref(), ((split_edge || TRAVEL_MODE_INACCESSIBLE == parsed_way.backward_travel_mode) ? ExtractionWay::oneway : ExtractionWay::bidirectional), - parsed_way.forward_speed, - name_id, - parsed_way.roundabout, - parsed_way.ignore_in_grid, - (0 < parsed_way.duration), - parsed_way.is_access_restricted, - parsed_way.forward_travel_mode, - split_edge)); + parsed_way.forward_speed, name_id, parsed_way.roundabout, parsed_way.ignore_in_grid, + (0 < parsed_way.duration), parsed_way.is_access_restricted, + parsed_way.forward_travel_mode, split_edge)); external_memory.used_node_id_list.push_back(first_node.ref()); }; const bool is_opposite_way = TRAVEL_MODE_INACCESSIBLE == parsed_way.forward_travel_mode; if (is_opposite_way) { - const_cast(parsed_way).forward_travel_mode = parsed_way.backward_travel_mode; - const_cast(parsed_way).backward_travel_mode = TRAVEL_MODE_INACCESSIBLE; - osrm::for_each_pair( - input_way.nodes().crbegin(), input_way.nodes().crend(), pair_wise_segment_split); + const_cast(parsed_way).forward_travel_mode = + parsed_way.backward_travel_mode; + const_cast(parsed_way).backward_travel_mode = TRAVEL_MODE_INACCESSIBLE; + osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(), + pair_wise_segment_split); external_memory.used_node_id_list.push_back(input_way.nodes().front().ref()); } else { - osrm::for_each_pair( - input_way.nodes().cbegin(), input_way.nodes().cend(), pair_wise_segment_split); + osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(), + pair_wise_segment_split); external_memory.used_node_id_list.push_back(input_way.nodes().back().ref()); } @@ -177,39 +174,30 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti if (split_edge) { // Only true if the way should be split - BOOST_ASSERT(parsed_way.backward_travel_mode>0); - auto pair_wise_segment_split_2 = [&](const osmium::NodeRef &first_node, - const osmium::NodeRef &last_node) + BOOST_ASSERT(parsed_way.backward_travel_mode > 0); + auto pair_wise_segment_split_2 = + [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node) { // SimpleLogger().Write() << "adding edge (" << last_node.ref() << "," << // first_node.ref() << "), bwd speed: " << parsed_way.backward_speed; - external_memory.all_edges_list.push_back( - InternalExtractorEdge(last_node.ref(), - first_node.ref(), - ExtractionWay::oneway, - parsed_way.backward_speed, - name_id, - parsed_way.roundabout, - parsed_way.ignore_in_grid, - (0 < parsed_way.duration), - parsed_way.is_access_restricted, - parsed_way.backward_travel_mode, - split_edge)); + external_memory.all_edges_list.push_back(InternalExtractorEdge( + last_node.ref(), first_node.ref(), ExtractionWay::oneway, parsed_way.backward_speed, + name_id, parsed_way.roundabout, parsed_way.ignore_in_grid, + (0 < parsed_way.duration), parsed_way.is_access_restricted, + parsed_way.backward_travel_mode, split_edge)); }; if (is_opposite_way) { // SimpleLogger().Write() << "opposite2"; - osrm::for_each_pair(input_way.nodes().crbegin(), - input_way.nodes().crend(), - pair_wise_segment_split_2); + osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(), + pair_wise_segment_split_2); external_memory.used_node_id_list.push_back(input_way.nodes().front().ref()); } else { - osrm::for_each_pair(input_way.nodes().cbegin(), - input_way.nodes().cend(), - pair_wise_segment_split_2); + osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(), + pair_wise_segment_split_2); external_memory.used_node_id_list.push_back(input_way.nodes().back().ref()); } diff --git a/extractor/extractor_options.cpp b/extractor/extractor_options.cpp index d14d8d9f8..8f58580cb 100644 --- a/extractor/extractor_options.cpp +++ b/extractor/extractor_options.cpp @@ -41,9 +41,8 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( - "config,c", - boost::program_options::value(&extractor_config.config_file_path) - ->default_value("extractor.ini"), + "config,c", boost::program_options::value( + &extractor_config.config_file_path)->default_value("extractor.ini"), "Path to a configuration file."); // declare a group of options that will be allowed both on command line and in config file @@ -60,10 +59,9 @@ bool ExtractorOptions::ParseArguments(int argc, char *argv[], ExtractorConfig &e // hidden options, will be allowed both on command line and in config file, but will not be // shown to the user boost::program_options::options_description hidden_options("Hidden options"); - hidden_options.add_options()( - "input,i", - boost::program_options::value(&extractor_config.input_path), - "Input file in .osm, .osm.bz2 or .osm.pbf format"); + hidden_options.add_options()("input,i", boost::program_options::value( + &extractor_config.input_path), + "Input file in .osm, .osm.bz2 or .osm.pbf format"); // positional option boost::program_options::positional_options_description positional_options; diff --git a/extractor/internal_extractor_edge.hpp b/extractor/internal_extractor_edge.hpp index 39616d345..2760f7256 100644 --- a/extractor/internal_extractor_edge.hpp +++ b/extractor/internal_extractor_edge.hpp @@ -55,8 +55,8 @@ struct InternalExtractorEdge bool is_access_restricted, TravelMode travel_mode, bool is_split) - : start(start), target(target), speed(speed), name_id(name_id), - direction(direction), is_roundabout(is_roundabout), is_in_tiny_cc(is_in_tiny_cc), + : start(start), target(target), speed(speed), name_id(name_id), direction(direction), + is_roundabout(is_roundabout), is_in_tiny_cc(is_in_tiny_cc), is_duration_set(is_duration_set), is_access_restricted(is_access_restricted), is_split(is_split), travel_mode(travel_mode) { @@ -65,12 +65,13 @@ struct InternalExtractorEdge // necessary static util functions for stxxl's sorting static InternalExtractorEdge min_value() { - return InternalExtractorEdge(0, 0, 0, 0, 0, false, false, false, false, TRAVEL_MODE_INACCESSIBLE, false); + return InternalExtractorEdge(0, 0, 0, 0, 0, false, false, false, false, + TRAVEL_MODE_INACCESSIBLE, false); } static InternalExtractorEdge max_value() { - return InternalExtractorEdge( - SPECIAL_NODEID, SPECIAL_NODEID, 0, 0, 0, false, false, false, false, TRAVEL_MODE_INACCESSIBLE, false); + return InternalExtractorEdge(SPECIAL_NODEID, SPECIAL_NODEID, 0, 0, 0, false, false, false, + false, TRAVEL_MODE_INACCESSIBLE, false); } NodeID start; @@ -78,11 +79,11 @@ struct InternalExtractorEdge double speed; unsigned name_id; short direction; - bool is_roundabout:1; - bool is_in_tiny_cc:1; - bool is_duration_set:1; - bool is_access_restricted:1; - bool is_split:1; + bool is_roundabout : 1; + bool is_in_tiny_cc : 1; + bool is_duration_set : 1; + bool is_access_restricted : 1; + bool is_split : 1; TravelMode travel_mode : 4; FixedPointCoordinate source_coordinate; diff --git a/extractor/restriction_parser.cpp b/extractor/restriction_parser.cpp index 2f53d33c3..dd4855508 100644 --- a/extractor/restriction_parser.cpp +++ b/extractor/restriction_parser.cpp @@ -85,8 +85,8 @@ void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state) { luabind::set_pcall_callback(&lua_error_callback); // get list of turn restriction exceptions - luabind::call_function( - lua_state, "get_exceptions", boost::ref(restriction_exceptions)); + luabind::call_function(lua_state, "get_exceptions", + boost::ref(restriction_exceptions)); const unsigned exception_count = restriction_exceptions.size(); SimpleLogger().Write() << "Found " << exception_count << " exceptions to turn restrictions:"; diff --git a/extractor/restriction_parser.hpp b/extractor/restriction_parser.hpp index d5adb4317..8347de306 100644 --- a/extractor/restriction_parser.hpp +++ b/extractor/restriction_parser.hpp @@ -46,7 +46,8 @@ class RestrictionParser public: // RestrictionParser(ScriptingEnvironment &scripting_environment); RestrictionParser(lua_State *lua_state); - mapbox::util::optional TryParse(const osmium::Relation &relation) const; + mapbox::util::optional + TryParse(const osmium::Relation &relation) const; private: void ReadUseRestrictionsSetting(lua_State *lua_state); diff --git a/extractor/scripting_environment.cpp b/extractor/scripting_environment.cpp index c51651e40..d50161c12 100644 --- a/extractor/scripting_environment.cpp +++ b/extractor/scripting_environment.cpp @@ -41,10 +41,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -namespace { +namespace +{ // wrapper method as luabind doesn't automatically overload funcs w/ default parameters -template -auto get_value_by_key(T const& object, const char *key) -> decltype(object.get_value_by_key(key)) +template +auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_value_by_key(key)) { return object.get_value_by_key(key, ""); } @@ -59,16 +60,14 @@ int lua_error_callback(lua_State *L) // This is so I can use my own function as } } - -ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) -: file_name(file_name) +ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_name(file_name) { SimpleLogger().Write() << "Using script " << file_name; } -void ScriptingEnvironment::init_lua_state(lua_State* lua_state) +void ScriptingEnvironment::init_lua_state(lua_State *lua_state) { - typedef double (osmium::Location::* location_member_ptr_type)() const; + typedef double (osmium::Location::*location_member_ptr_type)() const; luabind::open(lua_state); // open utility libraries string library; @@ -83,41 +82,44 @@ void ScriptingEnvironment::init_lua_state(lua_State* lua_state) luabind::def("parseDuration", parseDuration), luabind::class_>("vector") - .def("Add", static_cast::*)(const std::string &)>(&std::vector::push_back)), + .def("Add", static_cast::*)(const std::string &)>( + &std::vector::push_back)), luabind::class_("Location") - .def("lat", &osmium::Location::lat) - .def("lon", &osmium::Location::lon), + .def("lat", &osmium::Location::lat) + .def("lon", &osmium::Location::lon), luabind::class_("Node") - // .def("tags", &osmium::Node::tags) - .def("get_value_by_key", &osmium::Node::get_value_by_key) - .def("get_value_by_key", &get_value_by_key), + // .def("tags", &osmium::Node::tags) + .def("get_value_by_key", &osmium::Node::get_value_by_key) + .def("get_value_by_key", &get_value_by_key), luabind::class_("ResultNode") - .def_readwrite("traffic_lights", &ExtractionNode::traffic_lights) - .def_readwrite("barrier", &ExtractionNode::barrier), + .def_readwrite("traffic_lights", &ExtractionNode::traffic_lights) + .def_readwrite("barrier", &ExtractionNode::barrier), luabind::class_("ResultWay") - // .def(luabind::constructor<>()) - .def_readwrite("forward_speed", &ExtractionWay::forward_speed) - .def_readwrite("backward_speed", &ExtractionWay::backward_speed) - .def_readwrite("name", &ExtractionWay::name) - .def_readwrite("roundabout", &ExtractionWay::roundabout) - .def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted) - .def_readwrite("ignore_in_index", &ExtractionWay::ignore_in_grid) - .def_readwrite("duration", &ExtractionWay::duration) - .property("forward_mode", &ExtractionWay::get_forward_mode, &ExtractionWay::set_forward_mode) - .property("backward_mode", &ExtractionWay::get_backward_mode, &ExtractionWay::set_backward_mode) - .enum_("constants")[ - luabind::value("notSure", 0), - luabind::value("oneway", 1), - luabind::value("bidirectional", 2), - luabind::value("opposite", 3) - ], + // .def(luabind::constructor<>()) + .def_readwrite("forward_speed", &ExtractionWay::forward_speed) + .def_readwrite("backward_speed", &ExtractionWay::backward_speed) + .def_readwrite("name", &ExtractionWay::name) + .def_readwrite("roundabout", &ExtractionWay::roundabout) + .def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted) + .def_readwrite("ignore_in_index", &ExtractionWay::ignore_in_grid) + .def_readwrite("duration", &ExtractionWay::duration) + .property("forward_mode", &ExtractionWay::get_forward_mode, + &ExtractionWay::set_forward_mode) + .property("backward_mode", &ExtractionWay::get_backward_mode, + &ExtractionWay::set_backward_mode) + .enum_("constants")[ + luabind::value("notSure", 0), + luabind::value("oneway", 1), + luabind::value("bidirectional", 2), + luabind::value("opposite", 3) + ], luabind::class_("Way") - .def("get_value_by_key", &osmium::Way::get_value_by_key) - .def("get_value_by_key", &get_value_by_key) + .def("get_value_by_key", &osmium::Way::get_value_by_key) + .def("get_value_by_key", &get_value_by_key) ]; if (0 != luaL_dofile(lua_state, file_name.c_str())) @@ -133,7 +135,7 @@ lua_State *ScriptingEnvironment::get_lua_state() { std::lock_guard lock(init_mutex); bool initialized = false; - auto& ref = script_contexts.local(initialized); + auto &ref = script_contexts.local(initialized); if (!initialized) { std::shared_ptr state(luaL_newstate(), lua_close); diff --git a/extractor/scripting_environment.hpp b/extractor/scripting_environment.hpp index 6e0b079c9..8cc862a6a 100644 --- a/extractor/scripting_environment.hpp +++ b/extractor/scripting_environment.hpp @@ -44,8 +44,8 @@ class ScriptingEnvironment lua_State *get_lua_state(); private: - void init_lua_state(lua_State* lua_state); - std::mutex init_mutex; + void init_lua_state(lua_State *lua_state); + std::mutex init_mutex; std::string file_name; tbb::enumerable_thread_specific> script_contexts; }; diff --git a/routed.cpp b/routed.cpp index a0caac1f4..5768c3d03 100644 --- a/routed.cpp +++ b/routed.cpp @@ -75,15 +75,9 @@ int main(int argc, const char *argv[]) libosrm_config lib_config; - const unsigned init_result = GenerateServerProgramOptions(argc, - argv, - lib_config.server_paths, - ip_address, - ip_port, - requested_thread_num, - lib_config.use_shared_memory, - trial_run, - lib_config.max_locations_distance_table); + const unsigned init_result = GenerateServerProgramOptions( + argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num, + lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table); if (init_result == INIT_OK_DO_NOT_START_ENGINE) { return 0; @@ -119,8 +113,7 @@ int main(int argc, const char *argv[]) #endif OSRM osrm_lib(lib_config); - auto routing_server = - Server::CreateServer(ip_address, ip_port, requested_thread_num); + auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num); routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib); @@ -130,7 +123,11 @@ int main(int argc, const char *argv[]) } else { - std::packaged_task server_task([&]()->int{ routing_server->Run(); return 0; }); + std::packaged_task server_task([&]() -> int + { + routing_server->Run(); + return 0; + }); auto future = server_task.get_future(); std::thread server_thread(std::move(server_task)); @@ -159,7 +156,7 @@ int main(int argc, const char *argv[]) if (status == std::future_status::ready) { - server_thread.join(); + server_thread.join(); } else { diff --git a/tools/components.cpp b/tools/components.cpp index e9a96773a..f5fe73547 100644 --- a/tools/components.cpp +++ b/tools/components.cpp @@ -191,7 +191,7 @@ int main(int argc, char *argv[]) tarjan->run(); SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components() << " many components"; - SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " SCCs of size 1"; + SimpleLogger().Write() << "identified " << tarjan->get_size_one_count() << " size 1 SCCs"; // output TIMER_START(SCC_RUN_SETUP); diff --git a/tools/simpleclient.cpp b/tools/simpleclient.cpp index 0bb47599b..11b4f9a89 100644 --- a/tools/simpleclient.cpp +++ b/tools/simpleclient.cpp @@ -46,15 +46,9 @@ int main(int argc, const char *argv[]) int ip_port, requested_thread_num; bool trial_run = false; libosrm_config lib_config; - const unsigned init_result = GenerateServerProgramOptions(argc, - argv, - lib_config.server_paths, - ip_address, - ip_port, - requested_thread_num, - lib_config.use_shared_memory, - trial_run, - lib_config.max_locations_distance_table); + const unsigned init_result = GenerateServerProgramOptions( + argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num, + lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table); if (init_result == INIT_OK_DO_NOT_START_ENGINE) { diff --git a/unit_tests/data_structures/coordinate.cpp b/unit_tests/data_structures/coordinate.cpp index 1acb5e0df..c3c8b2a8e 100644 --- a/unit_tests/data_structures/coordinate.cpp +++ b/unit_tests/data_structures/coordinate.cpp @@ -44,8 +44,8 @@ BOOST_AUTO_TEST_CASE(regression_test_1347) float ratio; FixedPointCoordinate nearest_location; - float d2 = coordinate_calculation::ComputePerpendicularDistance(u, v, q, nearest_location, ratio); + float d2 = + coordinate_calculation::ComputePerpendicularDistance(u, v, q, nearest_location, ratio); BOOST_CHECK_LE(std::abs(d1 - d2), 0.01f); } -