reformat source files

This commit is contained in:
Dennis Luxen 2015-01-22 12:19:11 +01:00
parent 0f8c3b1960
commit baacd0e50c
23 changed files with 374 additions and 430 deletions

View File

@ -70,14 +70,15 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
time_stamp = localtime(&ltime); time_stamp = localtime(&ltime);
// log timestamp // log timestamp
SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday << "-" SimpleLogger().Write() << (time_stamp->tm_mday < 10 ? "0" : "") << time_stamp->tm_mday
<< (time_stamp->tm_mon + 1 < 10 ? "0" : "") << (time_stamp->tm_mon + 1) << "-" << "-" << (time_stamp->tm_mon + 1 < 10 ? "0" : "")
<< 1900 + time_stamp->tm_year << " " << (time_stamp->tm_hour < 10 ? "0" : "") << (time_stamp->tm_mon + 1) << "-" << 1900 + time_stamp->tm_year
<< time_stamp->tm_hour << ":" << (time_stamp->tm_min < 10 ? "0" : "") << time_stamp->tm_min << " " << (time_stamp->tm_hour < 10 ? "0" : "")
<< ":" << (time_stamp->tm_sec < 10 ? "0" : "") << time_stamp->tm_sec << " " << time_stamp->tm_hour << ":" << (time_stamp->tm_min < 10 ? "0" : "")
<< req.endpoint.to_string() << " " << req.referrer << time_stamp->tm_min << ":" << (time_stamp->tm_sec < 10 ? "0" : "")
<< (0 == req.referrer.length() ? "- " : " ") << req.agent << time_stamp->tm_sec << " " << req.endpoint.to_string() << " "
<< (0 == req.agent.length() ? "- " : " ") << request; << req.referrer << (0 == req.referrer.length() ? "- " : " ")
<< req.agent << (0 == req.agent.length() ? "- " : " ") << request;
RouteParameters route_parameters; RouteParameters route_parameters;
APIGrammarParser api_parser(&route_parameters); APIGrammarParser api_parser(&route_parameters);
@ -121,7 +122,8 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
return; return;
} }
// set headers // 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) if ("gpx" == route_parameters.output_format)
{ // gpx file { // gpx file
JSON::gpx_render(reply.content, json_result.values["route"]); JSON::gpx_render(reply.content, json_result.values["route"]);

View File

@ -39,9 +39,11 @@ double ComputeAngle::OfThreeFixedPointCoordinates(const FixedPointCoordinate &A,
const FixedPointCoordinate &B) const FixedPointCoordinate &B)
{ {
const double v1x = (A.lon - C.lon) / COORDINATE_PRECISION; 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 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; double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / M_PI;
while (angle < 0.) while (angle < 0.)

View File

@ -77,8 +77,7 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
nodes.swap(m_edge_based_node_list); nodes.swap(m_edge_based_node_list);
} }
void void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
const NodeID node_v, const NodeID node_v,
const unsigned component_id) const unsigned component_id)
{ {
@ -172,20 +171,13 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id); BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id);
// build edges // build edges
m_edge_based_node_list.emplace_back(forward_data.edgeBasedNodeID, m_edge_based_node_list.emplace_back(
reverse_data.edgeBasedNodeID, forward_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID,
current_edge_source_coordinate_id, current_edge_source_coordinate_id, current_edge_target_coordinate_id,
current_edge_target_coordinate_id, forward_data.nameID, forward_geometry[i].second,
forward_data.nameID, reverse_geometry[geometry_size - 1 - i].second, forward_dist_prefix_sum[i],
forward_geometry[i].second, reverse_dist_prefix_sum[i], m_geometry_compressor.GetPositionForID(e1),
reverse_geometry[geometry_size - 1 - i].second, component_id, i, forward_data.travel_mode, reverse_data.travel_mode);
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; current_edge_source_coordinate_id = current_edge_target_coordinate_id;
BOOST_ASSERT(m_edge_based_node_list.back().IsCompressed()); 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 || BOOST_ASSERT(forward_data.edgeBasedNodeID != SPECIAL_NODEID ||
reverse_data.edgeBasedNodeID != SPECIAL_NODEID); reverse_data.edgeBasedNodeID != SPECIAL_NODEID);
m_edge_based_node_list.emplace_back(forward_data.edgeBasedNodeID, m_edge_based_node_list.emplace_back(
reverse_data.edgeBasedNodeID, forward_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID, node_u, node_v,
node_u, forward_data.nameID, forward_data.distance, reverse_data.distance, 0, 0, SPECIAL_EDGEID,
node_v, component_id, 0, forward_data.travel_mode, reverse_data.travel_mode);
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()); BOOST_ASSERT(!m_edge_based_node_list.back().IsCompressed());
} }
} }
@ -245,7 +227,8 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u,
void EdgeBasedGraphFactory::FlushVectorToStream( void EdgeBasedGraphFactory::FlushVectorToStream(
std::ofstream &edge_data_file, std::vector<OriginalEdgeData> &original_edge_data_vector) const std::ofstream &edge_data_file, std::vector<OriginalEdgeData> &original_edge_data_vector) const
{ {
if (original_edge_data_vector.empty()) { if (original_edge_data_vector.empty())
{
return; return;
} }
edge_data_file.write((char *)&(original_edge_data_vector[0]), 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 &fwd_edge_data1 = m_node_based_graph->GetEdgeData(forward_e1);
const EdgeData &rev_edge_data1 = m_node_based_graph->GetEdgeData(reverse_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))) (m_node_based_graph->FindEdge(node_w, node_u) != m_node_based_graph->EndEdges(node_w)))
{ {
continue; continue;
} }
if ( // TODO: rename to IsCompatibleTo if ( // TODO: rename to IsCompatibleTo
fwd_edge_data1.IsEqualTo(fwd_edge_data2) && fwd_edge_data1.IsEqualTo(fwd_edge_data2) && rev_edge_data1.IsEqualTo(rev_edge_data2))
rev_edge_data1.IsEqualTo(rev_edge_data2))
{ {
// Get distances before graph is modified // Get distances before graph is modified
const int forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance; const int forward_weight1 = m_node_based_graph->GetEdgeData(forward_e1).distance;
@ -389,30 +372,21 @@ void EdgeBasedGraphFactory::CompressGeometry()
// update any involved turn restrictions // update any involved turn restrictions
m_restriction_map->FixupStartingTurnRestriction(node_u, node_v, node_w); m_restriction_map->FixupStartingTurnRestriction(node_u, node_v, node_w);
m_restriction_map->FixupArrivingTurnRestriction(node_u, node_v, m_restriction_map->FixupArrivingTurnRestriction(node_u, node_v, node_w,
node_w,
m_node_based_graph); m_node_based_graph);
m_restriction_map->FixupStartingTurnRestriction(node_w, node_v, node_u); m_restriction_map->FixupStartingTurnRestriction(node_w, node_v, node_u);
m_restriction_map->FixupArrivingTurnRestriction(node_w, m_restriction_map->FixupArrivingTurnRestriction(node_w, node_v, node_u,
node_v, m_node_based_graph);
node_u, m_node_based_graph);
// store compressed geometry in container // store compressed geometry in container
m_geometry_compressor.CompressEdge( m_geometry_compressor.CompressEdge(
forward_e1, forward_e1, forward_e2, node_v, node_w,
forward_e2,
node_v,
node_w,
forward_weight1 + forward_weight1 +
(add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0), (add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0),
forward_weight2); forward_weight2);
m_geometry_compressor.CompressEdge( m_geometry_compressor.CompressEdge(
reverse_e1, reverse_e1, reverse_e2, node_v, node_u, reverse_weight1,
reverse_e2,
node_v,
node_u,
reverse_weight1,
reverse_weight2 + reverse_weight2 +
(add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0)); (add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0));
++removed_node_count; ++removed_node_count;
@ -436,10 +410,10 @@ void EdgeBasedGraphFactory::CompressGeometry()
} }
} }
SimpleLogger().Write() << "new nodes: " << new_node_count << ", edges " << new_edge_count; SimpleLogger().Write() << "new nodes: " << new_node_count << ", edges " << new_edge_count;
SimpleLogger().Write() << "Node compression ratio: " << new_node_count / SimpleLogger().Write() << "Node compression ratio: "
(double)original_number_of_nodes; << new_node_count / (double)original_number_of_nodes;
SimpleLogger().Write() << "Edge compression ratio: " << new_edge_count / SimpleLogger().Write() << "Edge compression ratio: "
(double)original_number_of_edges; << new_edge_count / (double)original_number_of_edges;
} }
/** /**
@ -477,14 +451,16 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
SimpleLogger().Write() << "Identifying components of the (compressed) road network"; SimpleLogger().Write() << "Identifying components of the (compressed) road network";
// Run a BFS on the undirected graph and identify small components // Run a BFS on the undirected graph and identify small components
TarjanSCC<NodeBasedDynamicGraph> component_explorer( TarjanSCC<NodeBasedDynamicGraph> component_explorer(m_node_based_graph, *m_restriction_map,
m_node_based_graph, *m_restriction_map, m_barrier_nodes); m_barrier_nodes);
component_explorer.run(); 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"; << " (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"; << " (compressed) SCCs of size 1";
SimpleLogger().Write() << "generating edge-expanded nodes"; 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), const unsigned size_of_component = std::min(component_explorer.get_component_size(u),
component_explorer.get_component_size(v)); component_explorer.get_component_size(v));
const unsigned id_of_smaller_component = [u,v,&component_explorer] { const unsigned id_of_smaller_component = [u, v, &component_explorer]
if (component_explorer.get_component_size(u) < component_explorer.get_component_size(v)) {
if (component_explorer.get_component_size(u) <
component_explorer.get_component_size(v))
{ {
return component_explorer.get_component_id(u); return component_explorer.get_component_id(u);
} }
@ -544,9 +522,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
/** /**
* Actually it also generates OriginalEdgeData and serializes them... * Actually it also generates OriginalEdgeData and serializes them...
*/ */
void void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edge_data_filename, const std::string &original_edge_data_filename, lua_State *lua_state)
lua_State *lua_state)
{ {
SimpleLogger().Write() << "generating edge-expanded edges"; 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 // unpack last node of first segment if packed
const auto first_coordinate = m_node_info_list[(m_geometry_compressor.HasEntryForID(e1) ? const auto first_coordinate =
m_geometry_compressor.GetLastNodeIDOfBucket(e1) : m_node_info_list[(m_geometry_compressor.HasEntryForID(e1)
u)]; ? m_geometry_compressor.GetLastNodeIDOfBucket(e1)
: u)];
// unpack first node of second segment if packed // unpack first node of second segment if packed
const auto third_coordinate = m_node_info_list[(m_geometry_compressor.HasEntryForID(e2) ? const auto third_coordinate =
m_geometry_compressor.GetFirstNodeIDOfBucket(e2) : m_node_info_list[(m_geometry_compressor.HasEntryForID(e2)
w)]; ? m_geometry_compressor.GetFirstNodeIDOfBucket(e2)
: w)];
const double turn_angle = ComputeAngle::OfThreeFixedPointCoordinates( const double turn_angle = ComputeAngle::OfThreeFixedPointCoordinates(
first_coordinate, m_node_info_list[v], third_coordinate); 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( original_edge_data_vector.emplace_back(
(edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v), (edge_is_compressed ? m_geometry_compressor.GetPositionForID(e1) : v),
edge_data1.nameID, edge_data1.nameID, turn_instruction, edge_is_compressed,
turn_instruction,
edge_is_compressed,
edge_data2.travel_mode); edge_data2.travel_mode);
++original_edges_counter; ++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_data1.edgeBasedNodeID);
BOOST_ASSERT(SPECIAL_NODEID != edge_data2.edgeBasedNodeID); BOOST_ASSERT(SPECIAL_NODEID != edge_data2.edgeBasedNodeID);
m_edge_based_edge_list.emplace_back(EdgeBasedEdge(edge_data1.edgeBasedNodeID, m_edge_based_edge_list.emplace_back(
edge_data2.edgeBasedNodeID, EdgeBasedEdge(edge_data1.edgeBasedNodeID, edge_data2.edgeBasedNodeID,
m_edge_based_edge_list.size(), m_edge_based_edge_list.size(), distance, true, false));
distance,
true,
false));
} }
} }
} }
@ -727,7 +701,10 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co
// call lua profile to compute turn penalty // call lua profile to compute turn penalty
return luabind::call_function<int>(lua_state, "turn_function", 180. - angle); return luabind::call_function<int>(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; return 0;
} }
@ -735,8 +712,7 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co
TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID node_u, TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID node_u,
const NodeID node_v, const NodeID node_v,
const NodeID node_w, const NodeID node_w,
const double angle) const double angle) const
const
{ {
if (node_u == node_w) if (node_u == node_w)
{ {

View File

@ -138,13 +138,9 @@ int Prepare::Process(int argc, char *argv[])
static_assert(sizeof(ImportEdge) == 20, static_assert(sizeof(ImportEdge) == 20,
"changing ImportEdge type has influence on memory consumption!"); "changing ImportEdge type has influence on memory consumption!");
#endif #endif
NodeID number_of_node_based_nodes = NodeID number_of_node_based_nodes = readBinaryOSRMGraphFromStream(
readBinaryOSRMGraphFromStream(input_stream, input_stream, edge_list, barrier_node_list, traffic_light_list,
edge_list, &internal_to_external_node_map, restriction_list);
barrier_node_list,
traffic_light_list,
&internal_to_external_node_map,
restriction_list);
input_stream.close(); input_stream.close();
if (edge_list.empty()) if (edge_list.empty())
@ -162,11 +158,9 @@ int Prepare::Process(int argc, char *argv[])
DeallocatingVector<EdgeBasedEdge> edge_based_edge_list; DeallocatingVector<EdgeBasedEdge> edge_based_edge_list;
// init node_based_edge_list, edge_based_edge_list by edgeList // init node_based_edge_list, edge_based_edge_list by edgeList
number_of_edge_based_nodes = BuildEdgeExpandedGraph(lua_state, number_of_edge_based_nodes =
number_of_node_based_nodes, BuildEdgeExpandedGraph(lua_state, number_of_node_based_nodes, node_based_edge_list,
node_based_edge_list, edge_based_edge_list, speed_profile);
edge_based_edge_list,
speed_profile);
lua_close(lua_state); lua_close(lua_state);
TIMER_STOP(expansion); TIMER_STOP(expansion);
@ -343,8 +337,7 @@ bool Prepare::ParseArguments(int argc, char *argv[])
// declare a group of options that will be allowed only on command line // declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options"); boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"config,c", "config,c", boost::program_options::value<boost::filesystem::path>(&config_file_path)
boost::program_options::value<boost::filesystem::path>(&config_file_path)
->default_value("contractor.ini"), ->default_value("contractor.ini"),
"Path to a configuration file."); "Path to a configuration file.");
@ -354,12 +347,10 @@ bool Prepare::ParseArguments(int argc, char *argv[])
"restrictions,r", "restrictions,r",
boost::program_options::value<boost::filesystem::path>(&restrictions_path), boost::program_options::value<boost::filesystem::path>(&restrictions_path),
"Restrictions file in .osrm.restrictions format")( "Restrictions file in .osrm.restrictions format")(
"profile,p", "profile,p", boost::program_options::value<boost::filesystem::path>(&profile_path)
boost::program_options::value<boost::filesystem::path>(&profile_path)
->default_value("profile.lua"), ->default_value("profile.lua"),
"Path to LUA routing profile")( "Path to LUA routing profile")(
"threads,t", "threads,t", boost::program_options::value<unsigned int>(&requested_num_threads)
boost::program_options::value<unsigned int>(&requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()), ->default_value(tbb::task_scheduler_init::default_num_threads()),
"Number of threads to use"); "Number of threads to use");
@ -367,8 +358,7 @@ bool Prepare::ParseArguments(int argc, char *argv[])
// shown to the user // shown to the user
boost::program_options::options_description hidden_options("Hidden options"); boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()( hidden_options.add_options()(
"input,i", "input,i", boost::program_options::value<boost::filesystem::path>(&input_path),
boost::program_options::value<boost::filesystem::path>(&input_path),
"Input file in .osm, .osm.bz2 or .osm.pbf format"); "Input file in .osm, .osm.bz2 or .osm.pbf format");
// positional option // positional option
@ -397,7 +387,8 @@ bool Prepare::ParseArguments(int argc, char *argv[])
const auto &temp_config_path = option_variables["config"].as<boost::filesystem::path>(); const auto &temp_config_path = option_variables["config"].as<boost::filesystem::path>();
if (boost::filesystem::is_regular_file(temp_config_path)) if (boost::filesystem::is_regular_file(temp_config_path))
{ {
boost::program_options::store(boost::program_options::parse_config_file<char>(temp_config_path.string().c_str(), cmdline_options, true), boost::program_options::store(boost::program_options::parse_config_file<char>(
temp_config_path.string().c_str(), cmdline_options, true),
option_variables); option_variables);
} }
@ -458,9 +449,8 @@ void Prepare::CheckRestrictionsFile(FingerPrint &fingerprint_orig)
\brief Setups scripting environment (lua-scripting) \brief Setups scripting environment (lua-scripting)
Also initializes speed profile. Also initializes speed profile.
*/ */
bool bool Prepare::SetupScriptingEnvironment(
Prepare::SetupScriptingEnvironment(lua_State *lua_state, lua_State *lua_state, EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile)
EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile)
{ {
// open utility libraries string library; // open utility libraries string library;
luaL_openlibs(lua_state); luaL_openlibs(lua_state);
@ -509,14 +499,12 @@ Prepare::BuildEdgeExpandedGraph(lua_State *lua_state,
SimpleLogger().Write() << "Generating edge-expanded graph representation"; SimpleLogger().Write() << "Generating edge-expanded graph representation";
std::shared_ptr<NodeBasedDynamicGraph> node_based_graph = std::shared_ptr<NodeBasedDynamicGraph> node_based_graph =
NodeBasedDynamicGraphFromImportEdges(number_of_node_based_nodes, edge_list); NodeBasedDynamicGraphFromImportEdges(number_of_node_based_nodes, edge_list);
std::unique_ptr<RestrictionMap> restriction_map = osrm::make_unique<RestrictionMap>(restriction_list); std::unique_ptr<RestrictionMap> restriction_map =
osrm::make_unique<RestrictionMap>(restriction_list);
std::shared_ptr<EdgeBasedGraphFactory> edge_based_graph_factory = std::shared_ptr<EdgeBasedGraphFactory> edge_based_graph_factory =
std::make_shared<EdgeBasedGraphFactory>(node_based_graph, std::make_shared<EdgeBasedGraphFactory>(node_based_graph, std::move(restriction_map),
std::move(restriction_map), barrier_node_list, traffic_light_list,
barrier_node_list, internal_to_external_node_map, speed_profile);
traffic_light_list,
internal_to_external_node_map,
speed_profile);
edge_list.clear(); edge_list.clear();
edge_list.shrink_to_fit(); edge_list.shrink_to_fit();
@ -574,8 +562,6 @@ void Prepare::WriteNodeMapping()
void Prepare::BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list) void Prepare::BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list)
{ {
SimpleLogger().Write() << "building r-tree ..."; SimpleLogger().Write() << "building r-tree ...";
StaticRTree<EdgeBasedNode>(node_based_edge_list, StaticRTree<EdgeBasedNode>(node_based_edge_list, rtree_nodes_path.c_str(),
rtree_nodes_path.c_str(), rtree_leafs_path.c_str(), internal_to_external_node_map);
rtree_leafs_path.c_str(),
internal_to_external_node_map);
} }

View File

@ -93,8 +93,8 @@ void FixedPointCoordinate::Output(std::ostream &out) const
float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &other) const float FixedPointCoordinate::GetBearing(const FixedPointCoordinate &other) const
{ {
const float lon_delta = const float lon_delta = coordinate_calculation::deg_to_rad(lon / COORDINATE_PRECISION -
coordinate_calculation::deg_to_rad(lon / COORDINATE_PRECISION - other.lon / COORDINATE_PRECISION); other.lon / COORDINATE_PRECISION);
const float lat1 = coordinate_calculation::deg_to_rad(other.lat / 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 lat2 = coordinate_calculation::deg_to_rad(lat / COORDINATE_PRECISION);
const float y_value = std::sin(lon_delta) * std::cos(lat2); const float y_value = std::sin(lon_delta) * std::cos(lat2);

View File

@ -74,15 +74,15 @@ double coordinate_calculation::ApproximateDistance(const int lat1,
double coordinate_calculation::ApproximateDistance(const FixedPointCoordinate &coordinate_1, double coordinate_calculation::ApproximateDistance(const FixedPointCoordinate &coordinate_1,
const FixedPointCoordinate &coordinate_2) const FixedPointCoordinate &coordinate_2)
{ {
return ApproximateDistance( return ApproximateDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat,
coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); coordinate_2.lon);
} }
float coordinate_calculation::approx_euclidean_distance(const FixedPointCoordinate &coordinate_1, float coordinate_calculation::approx_euclidean_distance(const FixedPointCoordinate &coordinate_1,
const FixedPointCoordinate &coordinate_2) const FixedPointCoordinate &coordinate_2)
{ {
return approx_euclidean_distance( return approx_euclidean_distance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat,
coordinate_1.lat, coordinate_1.lon, coordinate_2.lat, coordinate_2.lon); coordinate_2.lon);
} }
float coordinate_calculation::approx_euclidean_distance(const int lat1, float coordinate_calculation::approx_euclidean_distance(const int lat1,
@ -105,22 +105,20 @@ float coordinate_calculation::approx_euclidean_distance(const int lat1,
return sqrt(x_value * x_value + y_value * y_value) * earth_radius; return sqrt(x_value * x_value + y_value * y_value) * earth_radius;
} }
float float coordinate_calculation::ComputePerpendicularDistance(
coordinate_calculation::ComputePerpendicularDistance(const FixedPointCoordinate &source_coordinate, const FixedPointCoordinate &source_coordinate,
const FixedPointCoordinate &target_coordinate, const FixedPointCoordinate &target_coordinate,
const FixedPointCoordinate &query_location) const FixedPointCoordinate &query_location)
{ {
float ratio; float ratio;
FixedPointCoordinate nearest_location; FixedPointCoordinate nearest_location;
return ComputePerpendicularDistance(source_coordinate, return ComputePerpendicularDistance(source_coordinate, target_coordinate, query_location,
target_coordinate, nearest_location, ratio);
query_location,
nearest_location,
ratio);
} }
float coordinate_calculation::ComputePerpendicularDistance(const FixedPointCoordinate &segment_source, float coordinate_calculation::ComputePerpendicularDistance(
const FixedPointCoordinate &segment_source,
const FixedPointCoordinate &segment_target, const FixedPointCoordinate &segment_target,
const FixedPointCoordinate &query_location, const FixedPointCoordinate &query_location,
FixedPointCoordinate &nearest_location, FixedPointCoordinate &nearest_location,
@ -197,8 +195,7 @@ float coordinate_calculation::ComputePerpendicularDistance(const FixedPointCoord
return approximate_distance; return approximate_distance;
} }
float float coordinate_calculation::perpendicular_distance_from_projected_coordinate(
coordinate_calculation::perpendicular_distance_from_projected_coordinate(
const FixedPointCoordinate &source_coordinate, const FixedPointCoordinate &source_coordinate,
const FixedPointCoordinate &target_coordinate, const FixedPointCoordinate &target_coordinate,
const FixedPointCoordinate &query_location, const FixedPointCoordinate &query_location,
@ -207,12 +204,9 @@ coordinate_calculation::perpendicular_distance_from_projected_coordinate(
float ratio; float ratio;
FixedPointCoordinate nearest_location; FixedPointCoordinate nearest_location;
return perpendicular_distance_from_projected_coordinate(source_coordinate, return perpendicular_distance_from_projected_coordinate(source_coordinate, target_coordinate,
target_coordinate, query_location, projected_coordinate,
query_location, nearest_location, ratio);
projected_coordinate,
nearest_location,
ratio);
} }
float coordinate_calculation::perpendicular_distance_from_projected_coordinate( float coordinate_calculation::perpendicular_distance_from_projected_coordinate(
@ -313,9 +307,8 @@ void coordinate_calculation::convertInternalCoordinateToString(const FixedPointC
output += tmp; output += tmp;
} }
void void coordinate_calculation::convertInternalReversedCoordinateToString(
coordinate_calculation::convertInternalReversedCoordinateToString(const FixedPointCoordinate &coord, const FixedPointCoordinate &coord, std::string &output)
std::string &output)
{ {
std::string tmp; std::string tmp;
tmp.reserve(23); tmp.reserve(23);

View File

@ -103,7 +103,8 @@ int main(const int argc, const char *argv[])
const bool lock_flags = MCL_CURRENT | MCL_FUTURE; const bool lock_flags = MCL_CURRENT | MCL_FUTURE;
if (-1 == mlockall(lock_flags)) 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 #endif
try try
@ -340,8 +341,8 @@ int main(const int argc, const char *argv[])
geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned)); geometry_input_stream.read((char *)&number_of_geometries_indices, sizeof(unsigned));
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_INDEX, shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_INDEX,
number_of_geometries_indices); number_of_geometries_indices);
boost::iostreams::seek( boost::iostreams::seek(geometry_input_stream,
geometry_input_stream, number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur); number_of_geometries_indices * sizeof(unsigned), BOOST_IOS::cur);
geometry_input_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned)); geometry_input_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));
shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_LIST, shared_layout_ptr->SetBlockSize<unsigned>(SharedDataLayout::GEOMETRIES_LIST,
number_of_compressed_geometries); number_of_compressed_geometries);
@ -410,8 +411,7 @@ int main(const int argc, const char *argv[])
unsigned *name_id_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>( unsigned *name_id_ptr = shared_layout_ptr->GetBlockPtr<unsigned, true>(
shared_memory_ptr, SharedDataLayout::NAME_ID_LIST); shared_memory_ptr, SharedDataLayout::NAME_ID_LIST);
TravelMode *travel_mode_ptr = TravelMode *travel_mode_ptr = shared_layout_ptr->GetBlockPtr<TravelMode, true>(
shared_layout_ptr->GetBlockPtr<TravelMode, true>(
shared_memory_ptr, SharedDataLayout::TRAVEL_MODE); shared_memory_ptr, SharedDataLayout::TRAVEL_MODE);
TurnInstruction *turn_instructions_ptr = TurnInstruction *turn_instructions_ptr =

View File

@ -83,32 +83,25 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
TIMER_STOP(erasing_dups); TIMER_STOP(erasing_dups);
std::cout << "ok, after " << TIMER_SEC(erasing_dups) << "s" << std::endl; std::cout << "ok, after " << TIMER_SEC(erasing_dups) << "s" << std::endl;
std::cout << "[extractor] Sorting all nodes ... " << std::flush; std::cout << "[extractor] Sorting all nodes ... " << std::flush;
TIMER_START(sorting_nodes); TIMER_START(sorting_nodes);
stxxl::sort(all_nodes_list.begin(), stxxl::sort(all_nodes_list.begin(), all_nodes_list.end(), ExternalMemoryNodeSTXXLCompare(),
all_nodes_list.end(),
ExternalMemoryNodeSTXXLCompare(),
stxxl_memory); stxxl_memory);
TIMER_STOP(sorting_nodes); TIMER_STOP(sorting_nodes);
std::cout << "ok, after " << TIMER_SEC(sorting_nodes) << "s" << std::endl; std::cout << "ok, after " << TIMER_SEC(sorting_nodes) << "s" << std::endl;
std::cout << "[extractor] Sorting used ways ... " << std::flush; std::cout << "[extractor] Sorting used ways ... " << std::flush;
TIMER_START(sort_ways); TIMER_START(sort_ways);
stxxl::sort(way_start_end_id_list.begin(), stxxl::sort(way_start_end_id_list.begin(), way_start_end_id_list.end(),
way_start_end_id_list.end(), FirstAndLastSegmentOfWayStxxlCompare(), stxxl_memory);
FirstAndLastSegmentOfWayStxxlCompare(),
stxxl_memory);
TIMER_STOP(sort_ways); TIMER_STOP(sort_ways);
std::cout << "ok, after " << TIMER_SEC(sort_ways) << "s" << std::endl; 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); TIMER_START(sort_restrictions);
stxxl::sort(restrictions_list.begin(), stxxl::sort(restrictions_list.begin(), restrictions_list.end(),
restrictions_list.end(), CmpRestrictionContainerByFrom(), stxxl_memory);
CmpRestrictionContainerByFrom(),
stxxl_memory);
TIMER_STOP(sort_restrictions); TIMER_STOP(sort_restrictions);
std::cout << "ok, after " << TIMER_SEC(sort_restrictions) << "s" << std::endl; 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; 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; const NodeID via_node_id = restrictions_iterator->restriction.via.node;
if (way_start_and_end_iterator->first_segment_source_id == via_node_id) 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; std::cout << "[extractor] Sorting restrictions. by to ... " << std::flush;
TIMER_START(sort_restrictions_to); TIMER_START(sort_restrictions_to);
stxxl::sort(restrictions_list.begin(), stxxl::sort(restrictions_list.begin(), restrictions_list.end(),
restrictions_list.end(), CmpRestrictionContainerByTo(), stxxl_memory);
CmpRestrictionContainerByTo(),
stxxl_memory);
TIMER_STOP(sort_restrictions_to); TIMER_STOP(sort_restrictions_to);
std::cout << "ok, after " << TIMER_SEC(sort_restrictions_to) << "s" << std::endl; 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; ++restrictions_iterator;
continue; 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; const NodeID via_node_id = restrictions_iterator->restriction.via.node;
if (way_start_and_end_iterator->first_segment_source_id == via_node_id) if (way_start_and_end_iterator->first_segment_source_id == via_node_id)
@ -267,7 +260,6 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
TIMER_STOP(sort_edges_by_start); TIMER_STOP(sort_edges_by_start);
std::cout << "ok, after " << TIMER_SEC(sort_edges_by_start) << "s" << std::endl; std::cout << "ok, after " << TIMER_SEC(sort_edges_by_start) << "s" << std::endl;
std::cout << "[extractor] Setting start coords ... " << std::flush; std::cout << "[extractor] Setting start coords ... " << std::flush;
TIMER_START(set_start_coords); TIMER_START(set_start_coords);
file_out_stream.write((char *)&number_of_used_edges, sizeof(unsigned)); 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 // Sort Edges by target
std::cout << "[extractor] Sorting edges by target ... " << std::flush; std::cout << "[extractor] Sorting edges by target ... " << std::flush;
TIMER_START(sort_edges_by_target); 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); TIMER_STOP(sort_edges_by_target);
std::cout << "ok, after " << TIMER_SEC(sort_edges_by_target) << "s" << std::endl; std::cout << "ok, after " << TIMER_SEC(sort_edges_by_target) << "s" << std::endl;
@ -329,15 +322,12 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
edge_iterator->target_coordinate.lon = node_iterator->lon; edge_iterator->target_coordinate.lon = node_iterator->lon;
const double distance = coordinate_calculation::approx_euclidean_distance( const double distance = coordinate_calculation::approx_euclidean_distance(
edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon,
edge_iterator->source_coordinate.lon, node_iterator->lat, node_iterator->lon);
node_iterator->lat,
node_iterator->lon);
const double weight = (distance * 10.) / (edge_iterator->speed / 3.6); const double weight = (distance * 10.) / (edge_iterator->speed / 3.6);
int integer_weight = std::max( int integer_weight = std::max(
1, 1, (int)std::floor(
(int)std::floor(
(edge_iterator->is_duration_set ? edge_iterator->speed : weight) + .5)); (edge_iterator->is_duration_set ? edge_iterator->speed : weight) + .5));
const int integer_distance = std::max(1, (int)distance); const int integer_distance = std::max(1, (int)distance);
const short zero = 0; const short zero = 0;
@ -371,19 +361,25 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
if (edge_iterator->is_roundabout) if (edge_iterator->is_roundabout)
{ {
file_out_stream.write((char *)&yes, sizeof(bool)); file_out_stream.write((char *)&yes, sizeof(bool));
} else { }
else
{
file_out_stream.write((char *)&no, sizeof(bool)); file_out_stream.write((char *)&no, sizeof(bool));
} }
if (edge_iterator->is_in_tiny_cc) if (edge_iterator->is_in_tiny_cc)
{ {
file_out_stream.write((char *)&yes, sizeof(bool)); file_out_stream.write((char *)&yes, sizeof(bool));
} else { }
else
{
file_out_stream.write((char *)&no, sizeof(bool)); file_out_stream.write((char *)&no, sizeof(bool));
} }
if (edge_iterator->is_access_restricted) if (edge_iterator->is_access_restricted)
{ {
file_out_stream.write((char *)&yes, sizeof(bool)); file_out_stream.write((char *)&yes, sizeof(bool));
} else { }
else
{
file_out_stream.write((char *)&no, sizeof(bool)); file_out_stream.write((char *)&no, sizeof(bool));
} }
@ -394,7 +390,9 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
if (edge_iterator->is_split) if (edge_iterator->is_split)
{ {
file_out_stream.write((char *)&yes, sizeof(bool)); file_out_stream.write((char *)&yes, sizeof(bool));
} else { }
else
{
file_out_stream.write((char *)&no, sizeof(bool)); file_out_stream.write((char *)&no, sizeof(bool));
} }
++number_of_used_edges; ++number_of_used_edges;
@ -420,7 +418,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
std::vector<unsigned> name_lengths; std::vector<unsigned> name_lengths;
for (const std::string &temp_string : name_list) for (const std::string &temp_string : name_list)
{ {
const unsigned string_length = std::min(static_cast<unsigned>(temp_string.length()), 255u); const unsigned string_length =
std::min(static_cast<unsigned>(temp_string.length()), 255u);
name_lengths.push_back(string_length); name_lengths.push_back(string_length);
total_length += string_length; total_length += string_length;
} }
@ -432,7 +431,8 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
// write all chars consecutively // write all chars consecutively
for (const std::string &temp_string : name_list) for (const std::string &temp_string : name_list)
{ {
const unsigned string_length = std::min(static_cast<unsigned>(temp_string.length()), 255u); const unsigned string_length =
std::min(static_cast<unsigned>(temp_string.length()), 255u);
name_file_stream.write(temp_string.c_str(), string_length); 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 " SimpleLogger().Write() << "Processed " << number_of_used_nodes << " nodes and "
<< number_of_used_edges << " edges"; << 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;
}
} }

View File

@ -39,7 +39,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class ExtractionContainers class ExtractionContainers
{ {
#ifndef _MSC_VER #ifndef _MSC_VER
constexpr static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? std::numeric_limits<int>::max() : std::numeric_limits<unsigned>::max()); constexpr static unsigned stxxl_memory =
((sizeof(std::size_t) == 4) ? std::numeric_limits<int>::max()
: std::numeric_limits<unsigned>::max());
#else #else
const static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? INT_MAX : UINT_MAX); const static unsigned stxxl_memory = ((sizeof(std::size_t) == 4) ? INT_MAX : UINT_MAX);
#endif #endif

View File

@ -31,10 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
struct ExtractionNode struct ExtractionNode
{ {
ExtractionNode() : traffic_lights(false), barrier(false) {} ExtractionNode() : traffic_lights(false), barrier(false) {}
void clear() void clear() { traffic_lights = barrier = false; }
{
traffic_lights = barrier = false;
}
bool traffic_lights; bool traffic_lights;
bool barrier; bool barrier;
}; };

View File

@ -52,10 +52,12 @@ struct ExtractionWay
} }
enum Directions enum Directions
{ notSure = 0, {
notSure = 0,
oneway, oneway,
bidirectional, bidirectional,
opposite }; opposite
};
// These accessor methods exists to support the depreciated "way.direction" access // These accessor methods exists to support the depreciated "way.direction" access
// in LUA. Since the direction attribute was removed from ExtractionWay, the // in LUA. Since the direction attribute was removed from ExtractionWay, the
@ -81,7 +83,8 @@ struct ExtractionWay
Directions get_direction() const 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; return Directions::bidirectional;
} }

View File

@ -99,7 +99,8 @@ int Extractor::Run(int argc, char *argv[])
} }
const unsigned recommended_num_threads = tbb::task_scheduler_init::default_num_threads(); 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); tbb::task_scheduler_init init(number_of_threads);
SimpleLogger().Write() << "Input file: " << extractor_config.input_path.filename().string(); SimpleLogger().Write() << "Input file: " << extractor_config.input_path.filename().string();
@ -160,7 +161,8 @@ int Extractor::Run(int argc, char *argv[])
{ {
// create a vector of iterators into the buffer // create a vector of iterators into the buffer
std::vector<osmium::memory::Buffer::const_iterator> osm_elements; std::vector<osmium::memory::Buffer::const_iterator> 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); osm_elements.push_back(iter);
} }
@ -170,7 +172,8 @@ int Extractor::Run(int argc, char *argv[])
resulting_restrictions.clear(); resulting_restrictions.clear();
// parse OSM entities in parallel, store in resulting vectors // parse OSM entities in parallel, store in resulting vectors
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, osm_elements.size()), tbb::parallel_for(
tbb::blocked_range<std::size_t>(0, osm_elements.size()),
[&](const tbb::blocked_range<std::size_t> &range) [&](const tbb::blocked_range<std::size_t> &range)
{ {
ExtractionNode result_node; ExtractionNode result_node;
@ -187,8 +190,7 @@ int Extractor::Run(int argc, char *argv[])
result_node.clear(); result_node.clear();
++number_of_nodes; ++number_of_nodes;
luabind::call_function<void>( luabind::call_function<void>(
local_state, local_state, "node_function",
"node_function",
boost::cref(static_cast<const osmium::Node &>(*entity)), boost::cref(static_cast<const osmium::Node &>(*entity)),
boost::ref(result_node)); boost::ref(result_node));
resulting_nodes.push_back(std::make_pair(x, result_node)); resulting_nodes.push_back(std::make_pair(x, result_node));
@ -197,16 +199,15 @@ int Extractor::Run(int argc, char *argv[])
result_way.clear(); result_way.clear();
++number_of_ways; ++number_of_ways;
luabind::call_function<void>( luabind::call_function<void>(
local_state, local_state, "way_function",
"way_function",
boost::cref(static_cast<const osmium::Way &>(*entity)), boost::cref(static_cast<const osmium::Way &>(*entity)),
boost::ref(result_way)); boost::ref(result_way));
resulting_ways.push_back(std::make_pair(x, result_way)); resulting_ways.push_back(std::make_pair(x, result_way));
break; break;
case osmium::item_type::relation: case osmium::item_type::relation:
++number_of_relations; ++number_of_relations;
resulting_restrictions.push_back( resulting_restrictions.push_back(restriction_parser.TryParse(
restriction_parser.TryParse(static_cast<const osmium::Relation &>(*entity))); static_cast<const osmium::Relation &>(*entity)));
break; break;
default: default:
++number_of_others; ++number_of_others;
@ -219,7 +220,8 @@ int Extractor::Run(int argc, char *argv[])
for (const auto &result : resulting_nodes) for (const auto &result : resulting_nodes)
{ {
extractor_callbacks->ProcessNode( extractor_callbacks->ProcessNode(
static_cast<const osmium::Node &>(*(osm_elements[result.first])), result.second); static_cast<const osmium::Node &>(*(osm_elements[result.first])),
result.second);
} }
for (const auto &result : resulting_ways) for (const auto &result : resulting_ways)
{ {
@ -238,11 +240,8 @@ int Extractor::Run(int argc, char *argv[])
unsigned nw = number_of_ways; unsigned nw = number_of_ways;
unsigned nr = number_of_relations; unsigned nr = number_of_relations;
unsigned no = number_of_others; unsigned no = number_of_others;
SimpleLogger().Write() << "Raw input contains " SimpleLogger().Write() << "Raw input contains " << nn << " nodes, " << nw << " ways, and "
<< nn << " nodes, " << nr << " relations, and " << no << " unknown entities";
<< nw << " ways, and "
<< nr << " relations, and "
<< no << " unknown entities";
extractor_callbacks.reset(); extractor_callbacks.reset();

View File

@ -51,13 +51,12 @@ ExtractorCallbacks::ExtractorCallbacks(ExtractionContainers &extraction_containe
void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node, void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node,
const ExtractionNode &result_node) const ExtractionNode &result_node)
{ {
external_memory.all_nodes_list.push_back({ external_memory.all_nodes_list.push_back(
static_cast<int>(input_node.location().lat() * COORDINATE_PRECISION), {static_cast<int>(input_node.location().lat() * COORDINATE_PRECISION),
static_cast<int>(input_node.location().lon() * COORDINATE_PRECISION), static_cast<int>(input_node.location().lon() * COORDINATE_PRECISION),
static_cast<NodeID>(input_node.id()), static_cast<NodeID>(input_node.id()),
result_node.barrier, result_node.barrier,
result_node.traffic_lights result_node.traffic_lights});
});
} }
void ExtractorCallbacks::ProcessRestriction( void ExtractorCallbacks::ProcessRestriction(
@ -69,7 +68,8 @@ void ExtractorCallbacks::ProcessRestriction(
// SimpleLogger().Write() << "from: " << restriction.get().restriction.from.node << // SimpleLogger().Write() << "from: " << restriction.get().restriction.from.node <<
// ",via: " << restriction.get().restriction.via.node << // ",via: " << restriction.get().restriction.via.node <<
// ", to: " << restriction.get().restriction.to.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! */ /** 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 // TODO: iterate all way segments and set duration corresponding to the length of each
// segment // segment
const_cast<ExtractionWay&>(parsed_way).forward_speed = parsed_way.duration / (input_way.nodes().size() - 1); const_cast<ExtractionWay &>(parsed_way).forward_speed =
const_cast<ExtractionWay&>(parsed_way).backward_speed = parsed_way.duration / (input_way.nodes().size() - 1); parsed_way.duration / (input_way.nodes().size() - 1);
const_cast<ExtractionWay &>(parsed_way).backward_speed =
parsed_way.duration / (input_way.nodes().size() - 1);
} }
if (std::numeric_limits<double>::epsilon() >= std::abs(-1. - parsed_way.forward_speed)) if (std::numeric_limits<double>::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_speed != parsed_way.backward_speed) ||
(parsed_way.forward_travel_mode != parsed_way.backward_travel_mode)); (parsed_way.forward_travel_mode != parsed_way.backward_travel_mode));
auto pair_wise_segment_split = [&](const osmium::NodeRef &first_node, auto pair_wise_segment_split =
const osmium::NodeRef &last_node) [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
{ {
// SimpleLogger().Write() << "adding edge (" << first_node.ref() << "," << // SimpleLogger().Write() << "adding edge (" << first_node.ref() << "," <<
// last_node.ref() << "), fwd speed: " << parsed_way.forward_speed; // last_node.ref() << "), fwd speed: " << parsed_way.forward_speed;
external_memory.all_edges_list.push_back(InternalExtractorEdge( external_memory.all_edges_list.push_back(InternalExtractorEdge(
first_node.ref(), first_node.ref(), last_node.ref(),
last_node.ref(),
((split_edge || TRAVEL_MODE_INACCESSIBLE == parsed_way.backward_travel_mode) ((split_edge || TRAVEL_MODE_INACCESSIBLE == parsed_way.backward_travel_mode)
? ExtractionWay::oneway ? ExtractionWay::oneway
: ExtractionWay::bidirectional), : ExtractionWay::bidirectional),
parsed_way.forward_speed, parsed_way.forward_speed, name_id, parsed_way.roundabout, parsed_way.ignore_in_grid,
name_id, (0 < parsed_way.duration), parsed_way.is_access_restricted,
parsed_way.roundabout, parsed_way.forward_travel_mode, split_edge));
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()); external_memory.used_node_id_list.push_back(first_node.ref());
}; };
const bool is_opposite_way = TRAVEL_MODE_INACCESSIBLE == parsed_way.forward_travel_mode; const bool is_opposite_way = TRAVEL_MODE_INACCESSIBLE == parsed_way.forward_travel_mode;
if (is_opposite_way) if (is_opposite_way)
{ {
const_cast<ExtractionWay&>(parsed_way).forward_travel_mode = parsed_way.backward_travel_mode; const_cast<ExtractionWay &>(parsed_way).forward_travel_mode =
parsed_way.backward_travel_mode;
const_cast<ExtractionWay &>(parsed_way).backward_travel_mode = TRAVEL_MODE_INACCESSIBLE; const_cast<ExtractionWay &>(parsed_way).backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
osrm::for_each_pair( osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(),
input_way.nodes().crbegin(), input_way.nodes().crend(), pair_wise_segment_split); pair_wise_segment_split);
external_memory.used_node_id_list.push_back(input_way.nodes().front().ref()); external_memory.used_node_id_list.push_back(input_way.nodes().front().ref());
} }
else else
{ {
osrm::for_each_pair( osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(),
input_way.nodes().cbegin(), input_way.nodes().cend(), pair_wise_segment_split); pair_wise_segment_split);
external_memory.used_node_id_list.push_back(input_way.nodes().back().ref()); external_memory.used_node_id_list.push_back(input_way.nodes().back().ref());
} }
@ -178,37 +175,28 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
if (split_edge) if (split_edge)
{ // Only true if the way should be split { // Only true if the way should be split
BOOST_ASSERT(parsed_way.backward_travel_mode > 0); BOOST_ASSERT(parsed_way.backward_travel_mode > 0);
auto pair_wise_segment_split_2 = [&](const osmium::NodeRef &first_node, auto pair_wise_segment_split_2 =
const osmium::NodeRef &last_node) [&](const osmium::NodeRef &first_node, const osmium::NodeRef &last_node)
{ {
// SimpleLogger().Write() << "adding edge (" << last_node.ref() << "," << // SimpleLogger().Write() << "adding edge (" << last_node.ref() << "," <<
// first_node.ref() << "), bwd speed: " << parsed_way.backward_speed; // first_node.ref() << "), bwd speed: " << parsed_way.backward_speed;
external_memory.all_edges_list.push_back( external_memory.all_edges_list.push_back(InternalExtractorEdge(
InternalExtractorEdge(last_node.ref(), last_node.ref(), first_node.ref(), ExtractionWay::oneway, parsed_way.backward_speed,
first_node.ref(), name_id, parsed_way.roundabout, parsed_way.ignore_in_grid,
ExtractionWay::oneway, (0 < parsed_way.duration), parsed_way.is_access_restricted,
parsed_way.backward_speed, parsed_way.backward_travel_mode, split_edge));
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) if (is_opposite_way)
{ {
// SimpleLogger().Write() << "opposite2"; // SimpleLogger().Write() << "opposite2";
osrm::for_each_pair(input_way.nodes().crbegin(), osrm::for_each_pair(input_way.nodes().crbegin(), input_way.nodes().crend(),
input_way.nodes().crend(),
pair_wise_segment_split_2); pair_wise_segment_split_2);
external_memory.used_node_id_list.push_back(input_way.nodes().front().ref()); external_memory.used_node_id_list.push_back(input_way.nodes().front().ref());
} }
else else
{ {
osrm::for_each_pair(input_way.nodes().cbegin(), osrm::for_each_pair(input_way.nodes().cbegin(), input_way.nodes().cend(),
input_way.nodes().cend(),
pair_wise_segment_split_2); pair_wise_segment_split_2);
external_memory.used_node_id_list.push_back(input_way.nodes().back().ref()); external_memory.used_node_id_list.push_back(input_way.nodes().back().ref());
} }

View File

@ -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 // declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options"); boost::program_options::options_description generic_options("Options");
generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")( generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"config,c", "config,c", boost::program_options::value<boost::filesystem::path>(
boost::program_options::value<boost::filesystem::path>(&extractor_config.config_file_path) &extractor_config.config_file_path)->default_value("extractor.ini"),
->default_value("extractor.ini"),
"Path to a configuration file."); "Path to a configuration file.");
// declare a group of options that will be allowed both on command line and in config file // declare a group of options that will be allowed both on command line and in config file
@ -60,9 +59,8 @@ 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 // hidden options, will be allowed both on command line and in config file, but will not be
// shown to the user // shown to the user
boost::program_options::options_description hidden_options("Hidden options"); boost::program_options::options_description hidden_options("Hidden options");
hidden_options.add_options()( hidden_options.add_options()("input,i", boost::program_options::value<boost::filesystem::path>(
"input,i", &extractor_config.input_path),
boost::program_options::value<boost::filesystem::path>(&extractor_config.input_path),
"Input file in .osm, .osm.bz2 or .osm.pbf format"); "Input file in .osm, .osm.bz2 or .osm.pbf format");
// positional option // positional option

View File

@ -55,8 +55,8 @@ struct InternalExtractorEdge
bool is_access_restricted, bool is_access_restricted,
TravelMode travel_mode, TravelMode travel_mode,
bool is_split) bool is_split)
: start(start), target(target), speed(speed), name_id(name_id), : start(start), target(target), speed(speed), name_id(name_id), direction(direction),
direction(direction), is_roundabout(is_roundabout), is_in_tiny_cc(is_in_tiny_cc), 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_duration_set(is_duration_set), is_access_restricted(is_access_restricted),
is_split(is_split), travel_mode(travel_mode) is_split(is_split), travel_mode(travel_mode)
{ {
@ -65,12 +65,13 @@ struct InternalExtractorEdge
// necessary static util functions for stxxl's sorting // necessary static util functions for stxxl's sorting
static InternalExtractorEdge min_value() 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() static InternalExtractorEdge max_value()
{ {
return InternalExtractorEdge( return InternalExtractorEdge(SPECIAL_NODEID, SPECIAL_NODEID, 0, 0, 0, false, false, false,
SPECIAL_NODEID, SPECIAL_NODEID, 0, 0, 0, false, false, false, false, TRAVEL_MODE_INACCESSIBLE, false); false, TRAVEL_MODE_INACCESSIBLE, false);
} }
NodeID start; NodeID start;

View File

@ -85,8 +85,8 @@ void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
{ {
luabind::set_pcall_callback(&lua_error_callback); luabind::set_pcall_callback(&lua_error_callback);
// get list of turn restriction exceptions // get list of turn restriction exceptions
luabind::call_function<void>( luabind::call_function<void>(lua_state, "get_exceptions",
lua_state, "get_exceptions", boost::ref(restriction_exceptions)); boost::ref(restriction_exceptions));
const unsigned exception_count = restriction_exceptions.size(); const unsigned exception_count = restriction_exceptions.size();
SimpleLogger().Write() << "Found " << exception_count SimpleLogger().Write() << "Found " << exception_count
<< " exceptions to turn restrictions:"; << " exceptions to turn restrictions:";

View File

@ -46,7 +46,8 @@ class RestrictionParser
public: public:
// RestrictionParser(ScriptingEnvironment &scripting_environment); // RestrictionParser(ScriptingEnvironment &scripting_environment);
RestrictionParser(lua_State *lua_state); RestrictionParser(lua_State *lua_state);
mapbox::util::optional<InputRestrictionContainer> TryParse(const osmium::Relation &relation) const; mapbox::util::optional<InputRestrictionContainer>
TryParse(const osmium::Relation &relation) const;
private: private:
void ReadUseRestrictionsSetting(lua_State *lua_state); void ReadUseRestrictionsSetting(lua_State *lua_state);

View File

@ -41,7 +41,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <osmium/osm.hpp> #include <osmium/osm.hpp>
#include <sstream> #include <sstream>
namespace { namespace
{
// wrapper method as luabind doesn't automatically overload funcs w/ default parameters // wrapper method as luabind doesn't automatically overload funcs w/ default parameters
template <class T> template <class T>
auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_value_by_key(key)) auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_value_by_key(key))
@ -59,9 +60,7 @@ 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; SimpleLogger().Write() << "Using script " << file_name;
} }
@ -83,7 +82,8 @@ void ScriptingEnvironment::init_lua_state(lua_State* lua_state)
luabind::def("parseDuration", parseDuration), luabind::def("parseDuration", parseDuration),
luabind::class_<std::vector<std::string>>("vector") luabind::class_<std::vector<std::string>>("vector")
.def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>(&std::vector<std::string>::push_back)), .def("Add", static_cast<void (std::vector<std::string>::*)(const std::string &)>(
&std::vector<std::string>::push_back)),
luabind::class_<osmium::Location>("Location") luabind::class_<osmium::Location>("Location")
.def<location_member_ptr_type>("lat", &osmium::Location::lat) .def<location_member_ptr_type>("lat", &osmium::Location::lat)
@ -107,8 +107,10 @@ void ScriptingEnvironment::init_lua_state(lua_State* lua_state)
.def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted) .def_readwrite("is_access_restricted", &ExtractionWay::is_access_restricted)
.def_readwrite("ignore_in_index", &ExtractionWay::ignore_in_grid) .def_readwrite("ignore_in_index", &ExtractionWay::ignore_in_grid)
.def_readwrite("duration", &ExtractionWay::duration) .def_readwrite("duration", &ExtractionWay::duration)
.property("forward_mode", &ExtractionWay::get_forward_mode, &ExtractionWay::set_forward_mode) .property("forward_mode", &ExtractionWay::get_forward_mode,
.property("backward_mode", &ExtractionWay::get_backward_mode, &ExtractionWay::set_backward_mode) &ExtractionWay::set_forward_mode)
.property("backward_mode", &ExtractionWay::get_backward_mode,
&ExtractionWay::set_backward_mode)
.enum_("constants")[ .enum_("constants")[
luabind::value("notSure", 0), luabind::value("notSure", 0),
luabind::value("oneway", 1), luabind::value("oneway", 1),

View File

@ -75,15 +75,9 @@ int main(int argc, const char *argv[])
libosrm_config lib_config; libosrm_config lib_config;
const unsigned init_result = GenerateServerProgramOptions(argc, const unsigned init_result = GenerateServerProgramOptions(
argv, argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
lib_config.server_paths, lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table);
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) if (init_result == INIT_OK_DO_NOT_START_ENGINE)
{ {
return 0; return 0;
@ -119,8 +113,7 @@ int main(int argc, const char *argv[])
#endif #endif
OSRM osrm_lib(lib_config); OSRM osrm_lib(lib_config);
auto routing_server = auto routing_server = Server::CreateServer(ip_address, ip_port, requested_thread_num);
Server::CreateServer(ip_address, ip_port, requested_thread_num);
routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib); routing_server->GetRequestHandlerPtr().RegisterRoutingMachine(&osrm_lib);
@ -130,7 +123,11 @@ int main(int argc, const char *argv[])
} }
else else
{ {
std::packaged_task<int()> server_task([&]()->int{ routing_server->Run(); return 0; }); std::packaged_task<int()> server_task([&]() -> int
{
routing_server->Run();
return 0;
});
auto future = server_task.get_future(); auto future = server_task.get_future();
std::thread server_thread(std::move(server_task)); std::thread server_thread(std::move(server_task));

View File

@ -191,7 +191,7 @@ int main(int argc, char *argv[])
tarjan->run(); tarjan->run();
SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components() SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
<< " many 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 // output
TIMER_START(SCC_RUN_SETUP); TIMER_START(SCC_RUN_SETUP);

View File

@ -46,15 +46,9 @@ int main(int argc, const char *argv[])
int ip_port, requested_thread_num; int ip_port, requested_thread_num;
bool trial_run = false; bool trial_run = false;
libosrm_config lib_config; libosrm_config lib_config;
const unsigned init_result = GenerateServerProgramOptions(argc, const unsigned init_result = GenerateServerProgramOptions(
argv, argc, argv, lib_config.server_paths, ip_address, ip_port, requested_thread_num,
lib_config.server_paths, lib_config.use_shared_memory, trial_run, lib_config.max_locations_distance_table);
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) if (init_result == INIT_OK_DO_NOT_START_ENGINE)
{ {

View File

@ -44,8 +44,8 @@ BOOST_AUTO_TEST_CASE(regression_test_1347)
float ratio; float ratio;
FixedPointCoordinate nearest_location; 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); BOOST_CHECK_LE(std::abs(d1 - d2), 0.01f);
} }