reformat Prepare.h/cpp with clang-format

This commit is contained in:
Dennis Luxen 2014-07-10 15:24:30 +02:00
parent bda9de0775
commit 2a19ded9d5
2 changed files with 54 additions and 57 deletions

View File

@ -55,14 +55,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <thread> #include <thread>
#include <vector> #include <vector>
Prepare::Prepare() : Prepare::Prepare() : requested_num_threads(1) {}
requested_num_threads(1)
{
}
Prepare::~Prepare() Prepare::~Prepare() {}
{
}
int Prepare::Process(int argc, char *argv[]) int Prepare::Process(int argc, char *argv[])
{ {
@ -70,20 +65,19 @@ int Prepare::Process(int argc, char *argv[])
TIMER_START(preparing); TIMER_START(preparing);
TIMER_START(expansion); TIMER_START(expansion);
if(!ParseArguments(argc, argv)) if (!ParseArguments(argc, argv))
{ return 0; {
} return 0;
}
if (!boost::filesystem::is_regular_file(input_path)) if (!boost::filesystem::is_regular_file(input_path))
{ {
SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() SimpleLogger().Write(logWARNING) << "Input file " << input_path.string() << " not found!";
<< " not found!";
return 1; return 1;
} }
if (!boost::filesystem::is_regular_file(profile_path)) if (!boost::filesystem::is_regular_file(profile_path))
{ {
SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() SimpleLogger().Write(logWARNING) << "Profile " << profile_path.string() << " not found!";
<< " not found!";
return 1; return 1;
} }
@ -131,15 +125,17 @@ int Prepare::Process(int argc, char *argv[])
EdgeBasedGraphFactory::SpeedProfileProperties speed_profile; EdgeBasedGraphFactory::SpeedProfileProperties speed_profile;
if(!SetupScriptingEnvironment(lua_state, speed_profile)) if (!SetupScriptingEnvironment(lua_state, speed_profile))
{ return 1;} {
return 1;
}
#ifdef WIN32 #ifdef WIN32
#pragma message ("Memory consumption on Windows can be higher due to different bit packing") #pragma message("Memory consumption on Windows can be higher due to different bit packing")
#else #else
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(in, readBinaryOSRMGraphFromStream(in,
edge_list, edge_list,
@ -164,8 +160,12 @@ 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
BuildEdgeExpandedGraph(lua_state, number_of_node_based_nodes, number_of_edge_based_nodes, BuildEdgeExpandedGraph(lua_state,
node_based_edge_list, edge_based_edge_list, speed_profile); number_of_node_based_nodes,
number_of_edge_based_nodes,
node_based_edge_list,
edge_based_edge_list,
speed_profile);
lua_close(lua_state); lua_close(lua_state);
TIMER_STOP(expansion); TIMER_STOP(expansion);
@ -218,8 +218,7 @@ int Prepare::Process(int argc, char *argv[])
max_used_node_id = std::max(max_used_node_id, edge.source); max_used_node_id = std::max(max_used_node_id, edge.source);
max_used_node_id = std::max(max_used_node_id, edge.target); max_used_node_id = std::max(max_used_node_id, edge.target);
} }
SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes SimpleLogger().Write(logDEBUG) << "input graph has " << number_of_edge_based_nodes << " nodes";
<< " nodes";
SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes"; SimpleLogger().Write(logDEBUG) << "contracted graph has " << max_used_node_id << " nodes";
max_used_node_id += 1; max_used_node_id += 1;
@ -243,7 +242,7 @@ int Prepare::Process(int argc, char *argv[])
position += edge - last_edge; // remove position += edge - last_edge; // remove
} }
for(const auto sentinel_counter : boost::irange(max_used_node_id, (unsigned)node_array.size())) for (const auto sentinel_counter : boost::irange(max_used_node_id, (unsigned)node_array.size()))
{ {
// sentinel element, guarded against underflow // sentinel element, guarded against underflow
node_array[sentinel_counter].first_edge = contracted_edge_count; node_array[sentinel_counter].first_edge = contracted_edge_count;
@ -262,7 +261,7 @@ int Prepare::Process(int argc, char *argv[])
if (node_array_size > 0) if (node_array_size > 0)
{ {
hsgr_output_stream.write((char *)&node_array[0], hsgr_output_stream.write((char *)&node_array[0],
sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size); sizeof(StaticGraph<EdgeData>::NodeArrayEntry) * node_array_size);
} }
// serialize all edges // serialize all edges
@ -271,7 +270,7 @@ int Prepare::Process(int argc, char *argv[])
int number_of_used_edges = 0; int number_of_used_edges = 0;
StaticGraph<EdgeData>::EdgeArrayEntry current_edge; StaticGraph<EdgeData>::EdgeArrayEntry current_edge;
for (const auto edge : boost::irange(0u, (unsigned) contracted_edge_list.size())) for (const auto edge : boost::irange(0u, (unsigned)contracted_edge_list.size()))
{ {
// no eigen loops // no eigen loops
BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target); BOOST_ASSERT(contracted_edge_list[edge].source != contracted_edge_list[edge].target);
@ -283,10 +282,10 @@ int Prepare::Process(int argc, char *argv[])
#ifndef NDEBUG #ifndef NDEBUG
if (current_edge.data.distance <= 0) if (current_edge.data.distance <= 0)
{ {
SimpleLogger().Write(logWARNING) SimpleLogger().Write(logWARNING) << "Edge: " << edge
<< "Edge: " << edge << ",source: " << contracted_edge_list[edge].source << ",source: " << contracted_edge_list[edge].source
<< ", target: " << contracted_edge_list[edge].target << ", target: " << contracted_edge_list[edge].target
<< ", dist: " << current_edge.data.distance; << ", dist: " << current_edge.data.distance;
SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node " SimpleLogger().Write(logWARNING) << "Failed at adjacency list of node "
<< contracted_edge_list[edge].source << "/" << contracted_edge_list[edge].source << "/"
@ -304,16 +303,13 @@ int Prepare::Process(int argc, char *argv[])
TIMER_STOP(preparing); TIMER_STOP(preparing);
SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds"; SimpleLogger().Write() << "Preprocessing : " << TIMER_SEC(preparing) << " seconds";
SimpleLogger().Write() << "Expansion : " SimpleLogger().Write() << "Expansion : " << (number_of_node_based_nodes / TIMER_SEC(expansion))
<< (number_of_node_based_nodes / TIMER_SEC(expansion))
<< " nodes/sec and " << " nodes/sec and "
<< (number_of_edge_based_nodes / TIMER_SEC(expansion)) << (number_of_edge_based_nodes / TIMER_SEC(expansion)) << " edges/sec";
<< " edges/sec";
SimpleLogger().Write() << "Contraction: " SimpleLogger().Write() << "Contraction: "
<< (number_of_edge_based_nodes / TIMER_SEC(contraction)) << (number_of_edge_based_nodes / TIMER_SEC(contraction))
<< " nodes/sec and " << " nodes/sec and " << number_of_used_edges / TIMER_SEC(contraction)
<< number_of_used_edges / TIMER_SEC(contraction)
<< " edges/sec"; << " edges/sec";
node_array.clear(); node_array.clear();
@ -333,8 +329,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", generic_options.add_options()("version,v", "Show version")("help,h", "Show this help message")(
"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"),
@ -351,7 +346,8 @@ bool Prepare::ParseArguments(int argc, char *argv[])
->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)->default_value(tbb::task_scheduler_init::default_num_threads()), boost::program_options::value<unsigned int>(&requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
"Number of threads to use"); "Number of threads to use");
// 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
@ -433,7 +429,7 @@ void Prepare::CheckRestrictionsFile(FingerPrint &fingerprint_orig)
if (number_of_usable_restrictions > 0) if (number_of_usable_restrictions > 0)
{ {
restriction_stream.read((char *)&(restriction_list[0]), restriction_stream.read((char *)&(restriction_list[0]),
number_of_usable_restrictions * sizeof(TurnRestriction)); number_of_usable_restrictions * sizeof(TurnRestriction));
} }
restriction_stream.close(); restriction_stream.close();
} }
@ -442,7 +438,9 @@ 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 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; // open utility libraries string library;
luaL_openlibs(lua_state); luaL_openlibs(lua_state);
@ -482,11 +480,11 @@ bool Prepare::SetupScriptingEnvironment(lua_State *lua_state, EdgeBasedGraphFact
\brief Building an edge-expanded graph from node-based input and turn restrictions \brief Building an edge-expanded graph from node-based input and turn restrictions
*/ */
void Prepare::BuildEdgeExpandedGraph(lua_State *lua_state, void Prepare::BuildEdgeExpandedGraph(lua_State *lua_state,
NodeID number_of_node_based_nodes, NodeID number_of_node_based_nodes,
unsigned &number_of_edge_based_nodes, unsigned &number_of_edge_based_nodes,
std::vector<EdgeBasedNode> &node_based_edge_list, std::vector<EdgeBasedNode> &node_based_edge_list,
DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list, DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile) EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile)
{ {
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 =
@ -515,10 +513,10 @@ void Prepare::BuildEdgeExpandedGraph(lua_State *lua_state,
number_of_edge_based_nodes = edge_based_graph_factory->GetNumberOfEdgeBasedNodes(); number_of_edge_based_nodes = edge_based_graph_factory->GetNumberOfEdgeBasedNodes();
BOOST_ASSERT(number_of_edge_based_nodes != std::numeric_limits<unsigned>::max()); BOOST_ASSERT(number_of_edge_based_nodes != std::numeric_limits<unsigned>::max());
#ifndef WIN32 #ifndef WIN32
static_assert(sizeof(EdgeBasedEdge) == 16, static_assert(sizeof(EdgeBasedEdge) == 16,
"changing ImportEdge type has influence on memory consumption!"); "changing ImportEdge type has influence on memory consumption!");
#endif #endif
edge_based_graph_factory->GetEdgeBasedEdges(edge_based_edge_list); edge_based_graph_factory->GetEdgeBasedEdges(edge_based_edge_list);
edge_based_graph_factory->GetEdgeBasedNodes(node_based_edge_list); edge_based_graph_factory->GetEdgeBasedNodes(node_based_edge_list);
@ -539,7 +537,7 @@ void Prepare::WriteNodeMapping()
if (size_of_mapping > 0) if (size_of_mapping > 0)
{ {
node_stream.write((char *)&(internal_to_external_node_map[0]), node_stream.write((char *)&(internal_to_external_node_map[0]),
size_of_mapping * sizeof(NodeInfo)); size_of_mapping * sizeof(NodeInfo));
} }
node_stream.close(); node_stream.close();
internal_to_external_node_map.clear(); internal_to_external_node_map.clear();
@ -559,4 +557,3 @@ void Prepare::BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list)
rtree_leafs_path.c_str(), rtree_leafs_path.c_str(),
internal_to_external_node_map); internal_to_external_node_map);
} }

View File

@ -17,22 +17,22 @@
*/ */
class Prepare class Prepare
{ {
public: public:
typedef QueryEdge::EdgeData EdgeData; typedef QueryEdge::EdgeData EdgeData;
typedef DynamicGraph<EdgeData>::InputEdge InputEdge; typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
typedef StaticGraph<EdgeData>::InputEdge StaticEdge; typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
explicit Prepare(); explicit Prepare();
Prepare(const Prepare&) = delete; Prepare(const Prepare &) = delete;
~Prepare(); ~Prepare();
int Process(int argc, char *argv[]); int Process(int argc, char *argv[]);
protected: protected:
bool ParseArguments(int argc, char *argv[]); bool ParseArguments(int argc, char *argv[]);
void CheckRestrictionsFile(FingerPrint &fingerprint_orig); void CheckRestrictionsFile(FingerPrint &fingerprint_orig);
bool SetupScriptingEnvironment(lua_State *myLuaState, EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile); bool SetupScriptingEnvironment(lua_State *myLuaState,
EdgeBasedGraphFactory::SpeedProfileProperties &speed_profile);
void BuildEdgeExpandedGraph(lua_State *myLuaState, void BuildEdgeExpandedGraph(lua_State *myLuaState,
NodeID nodeBasedNodeNumber, NodeID nodeBasedNodeNumber,
unsigned &nodeBasedEdgesNumber, unsigned &nodeBasedEdgesNumber,
@ -42,7 +42,7 @@ protected:
void WriteNodeMapping(); void WriteNodeMapping();
void BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list); void BuildRTree(std::vector<EdgeBasedNode> &node_based_edge_list);
private: private:
std::vector<NodeInfo> internal_to_external_node_map; std::vector<NodeInfo> internal_to_external_node_map;
std::vector<TurnRestriction> restriction_list; std::vector<TurnRestriction> restriction_list;
std::vector<NodeID> barrier_node_list; std::vector<NodeID> barrier_node_list;