fix several errors reported by OCLint:

- rename variable with short name
- fix inverted logic
- rename members in SpeedProfile
This commit is contained in:
Dennis Luxen 2014-08-13 11:00:16 +02:00
parent d5130d9fe4
commit 6f01f580ca
3 changed files with 79 additions and 87 deletions

View File

@ -78,29 +78,29 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
} }
void void
EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID u, const NodeID v, const bool belongs_to_tiny_cc) EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeID node_v, const bool belongs_to_tiny_cc)
{ {
// merge edges together into one EdgeBasedNode // merge edges together into one EdgeBasedNode
BOOST_ASSERT(u != SPECIAL_NODEID); BOOST_ASSERT(node_u != SPECIAL_NODEID);
BOOST_ASSERT(v != SPECIAL_NODEID); BOOST_ASSERT(node_v != SPECIAL_NODEID);
// find forward edge id and // find forward edge id and
const EdgeID e1 = m_node_based_graph->FindEdge(u, v); const EdgeID e1 = m_node_based_graph->FindEdge(node_u, node_v);
BOOST_ASSERT(e1 != SPECIAL_EDGEID); BOOST_ASSERT(e1 != SPECIAL_EDGEID);
const EdgeData &forward_data = m_node_based_graph->GetEdgeData(e1); const EdgeData &forward_data = m_node_based_graph->GetEdgeData(e1);
// find reverse edge id and // find reverse edge id and
const EdgeID e2 = m_node_based_graph->FindEdge(v, u); const EdgeID e2 = m_node_based_graph->FindEdge(node_v, node_u);
#ifndef NDEBUG #ifndef NDEBUG
if (e2 == m_node_based_graph->EndEdges(v)) if (e2 == m_node_based_graph->EndEdges(node_v))
{ {
SimpleLogger().Write(logWARNING) << "Did not find edge (" << v << "," << u << ")"; SimpleLogger().Write(logWARNING) << "Did not find edge (" << node_v << "," << node_u << ")";
} }
#endif #endif
BOOST_ASSERT(e2 != SPECIAL_EDGEID); BOOST_ASSERT(e2 != SPECIAL_EDGEID);
BOOST_ASSERT(e2 < m_node_based_graph->EndEdges(v)); BOOST_ASSERT(e2 < m_node_based_graph->EndEdges(node_v));
const EdgeData &reverse_data = m_node_based_graph->GetEdgeData(e2); const EdgeData &reverse_data = m_node_based_graph->GetEdgeData(e2);
if (forward_data.edgeBasedNodeID == SPECIAL_NODEID && if (forward_data.edgeBasedNodeID == SPECIAL_NODEID &&
@ -150,7 +150,7 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID u, const NodeID v, const
// BOOST_ASSERT(reverse_data.distance >= temp_sum); // BOOST_ASSERT(reverse_data.distance >= temp_sum);
} }
NodeID current_edge_source_coordinate_id = u; NodeID current_edge_source_coordinate_id = node_u;
if (SPECIAL_NODEID != forward_data.edgeBasedNodeID) if (SPECIAL_NODEID != forward_data.edgeBasedNodeID)
{ {
@ -186,14 +186,14 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID u, const NodeID v, const
BOOST_ASSERT(m_edge_based_node_list.back().IsCompressed()); BOOST_ASSERT(m_edge_based_node_list.back().IsCompressed());
BOOST_ASSERT(u != m_edge_based_node_list.back().u || BOOST_ASSERT(node_u != m_edge_based_node_list.back().u ||
v != m_edge_based_node_list.back().v); node_v != m_edge_based_node_list.back().v);
BOOST_ASSERT(u != m_edge_based_node_list.back().v || BOOST_ASSERT(node_u != m_edge_based_node_list.back().v ||
v != m_edge_based_node_list.back().u); node_v != m_edge_based_node_list.back().u);
} }
BOOST_ASSERT(current_edge_source_coordinate_id == v); BOOST_ASSERT(current_edge_source_coordinate_id == node_v);
BOOST_ASSERT(m_edge_based_node_list.back().IsCompressed()); BOOST_ASSERT(m_edge_based_node_list.back().IsCompressed());
} }
else else
@ -222,8 +222,8 @@ EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID u, const NodeID v, const
m_edge_based_node_list.emplace_back(forward_data.edgeBasedNodeID, m_edge_based_node_list.emplace_back(forward_data.edgeBasedNodeID,
reverse_data.edgeBasedNodeID, reverse_data.edgeBasedNodeID,
u, node_u,
v, node_v,
forward_data.nameID, forward_data.nameID,
forward_data.distance, forward_data.distance,
reverse_data.distance, reverse_data.distance,
@ -284,61 +284,61 @@ void EdgeBasedGraphFactory::CompressGeometry()
const unsigned original_number_of_nodes = m_node_based_graph->GetNumberOfNodes(); const unsigned original_number_of_nodes = m_node_based_graph->GetNumberOfNodes();
const unsigned original_number_of_edges = m_node_based_graph->GetNumberOfEdges(); const unsigned original_number_of_edges = m_node_based_graph->GetNumberOfEdges();
Percent p(original_number_of_nodes); Percent progress(original_number_of_nodes);
unsigned removed_node_count = 0; unsigned removed_node_count = 0;
for (const NodeID v : osrm::irange(0u, original_number_of_nodes)) for (const NodeID node_v : osrm::irange(0u, original_number_of_nodes))
{ {
p.printStatus(v); progress.printStatus(node_v);
// only contract degree 2 vertices // only contract degree 2 vertices
if (2 != m_node_based_graph->GetOutDegree(v)) if (2 != m_node_based_graph->GetOutDegree(node_v))
{ {
continue; continue;
} }
// don't contract barrier node // don't contract barrier node
if (m_barrier_nodes.end() != m_barrier_nodes.find(v)) if (m_barrier_nodes.end() != m_barrier_nodes.find(node_v))
{ {
continue; continue;
} }
// check if v is a via node for a turn restriction, i.e. a 'directed' barrier node // check if v is a via node for a turn restriction, i.e. a 'directed' barrier node
if (m_restriction_map->IsViaNode(v)) if (m_restriction_map->IsViaNode(node_v))
{ {
continue; continue;
} }
const bool reverse_edge_order = const bool reverse_edge_order =
!(m_node_based_graph->GetEdgeData(m_node_based_graph->BeginEdges(v)).forward); !(m_node_based_graph->GetEdgeData(m_node_based_graph->BeginEdges(node_v)).forward);
const EdgeID forward_e2 = m_node_based_graph->BeginEdges(v) + reverse_edge_order; const EdgeID forward_e2 = m_node_based_graph->BeginEdges(node_v) + reverse_edge_order;
BOOST_ASSERT(SPECIAL_EDGEID != forward_e2); BOOST_ASSERT(SPECIAL_EDGEID != forward_e2);
const EdgeID reverse_e2 = m_node_based_graph->BeginEdges(v) + 1 - reverse_edge_order; const EdgeID reverse_e2 = m_node_based_graph->BeginEdges(node_v) + 1 - reverse_edge_order;
BOOST_ASSERT(SPECIAL_EDGEID != reverse_e2); BOOST_ASSERT(SPECIAL_EDGEID != reverse_e2);
const EdgeData &fwd_edge_data2 = m_node_based_graph->GetEdgeData(forward_e2); const EdgeData &fwd_edge_data2 = m_node_based_graph->GetEdgeData(forward_e2);
const EdgeData &rev_edge_data2 = m_node_based_graph->GetEdgeData(reverse_e2); const EdgeData &rev_edge_data2 = m_node_based_graph->GetEdgeData(reverse_e2);
const NodeID w = m_node_based_graph->GetTarget(forward_e2); const NodeID node_w = m_node_based_graph->GetTarget(forward_e2);
BOOST_ASSERT(SPECIAL_NODEID != w); BOOST_ASSERT(SPECIAL_NODEID != node_w);
BOOST_ASSERT(v != w); BOOST_ASSERT(node_v != node_w);
const NodeID u = m_node_based_graph->GetTarget(reverse_e2); const NodeID node_u = m_node_based_graph->GetTarget(reverse_e2);
BOOST_ASSERT(SPECIAL_NODEID != u); BOOST_ASSERT(SPECIAL_NODEID != node_u);
BOOST_ASSERT(u != v); BOOST_ASSERT(node_u != node_v);
const EdgeID forward_e1 = m_node_based_graph->FindEdge(u, v); const EdgeID forward_e1 = m_node_based_graph->FindEdge(node_u, node_v);
BOOST_ASSERT(m_node_based_graph->EndEdges(u) != forward_e1); BOOST_ASSERT(m_node_based_graph->EndEdges(node_u) != forward_e1);
BOOST_ASSERT(SPECIAL_EDGEID != forward_e1); BOOST_ASSERT(SPECIAL_EDGEID != forward_e1);
BOOST_ASSERT(v == m_node_based_graph->GetTarget(forward_e1)); BOOST_ASSERT(node_v == m_node_based_graph->GetTarget(forward_e1));
const EdgeID reverse_e1 = m_node_based_graph->FindEdge(w, v); const EdgeID reverse_e1 = m_node_based_graph->FindEdge(node_w, node_v);
BOOST_ASSERT(SPECIAL_EDGEID != reverse_e1); BOOST_ASSERT(SPECIAL_EDGEID != reverse_e1);
BOOST_ASSERT(v == m_node_based_graph->GetTarget(reverse_e1)); BOOST_ASSERT(node_v == m_node_based_graph->GetTarget(reverse_e1));
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(u, w) != m_node_based_graph->EndEdges(u)) || if ((m_node_based_graph->FindEdge(node_u, node_w) != m_node_based_graph->EndEdges(node_u)) ||
(m_node_based_graph->FindEdge(w, u) != m_node_based_graph->EndEdges(w))) (m_node_based_graph->FindEdge(node_w, node_u) != m_node_based_graph->EndEdges(node_w)))
{ {
continue; continue;
} }
@ -361,7 +361,7 @@ void EdgeBasedGraphFactory::CompressGeometry()
BOOST_ASSERT(0 != forward_weight2); BOOST_ASSERT(0 != forward_weight2);
const bool add_traffic_signal_penalty = const bool add_traffic_signal_penalty =
(m_traffic_lights.find(v) != m_traffic_lights.end()); (m_traffic_lights.find(node_v) != m_traffic_lights.end());
// add weight of e2's to e1 // add weight of e2's to e1
m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance; m_node_based_graph->GetEdgeData(forward_e1).distance += fwd_edge_data2.distance;
@ -369,43 +369,43 @@ void EdgeBasedGraphFactory::CompressGeometry()
if (add_traffic_signal_penalty) if (add_traffic_signal_penalty)
{ {
m_node_based_graph->GetEdgeData(forward_e1).distance += m_node_based_graph->GetEdgeData(forward_e1).distance +=
speed_profile.trafficSignalPenalty; speed_profile.traffic_signal_penalty;
m_node_based_graph->GetEdgeData(reverse_e1).distance += m_node_based_graph->GetEdgeData(reverse_e1).distance +=
speed_profile.trafficSignalPenalty; speed_profile.traffic_signal_penalty;
} }
// extend e1's to targets of e2's // extend e1's to targets of e2's
m_node_based_graph->SetTarget(forward_e1, w); m_node_based_graph->SetTarget(forward_e1, node_w);
m_node_based_graph->SetTarget(reverse_e1, u); m_node_based_graph->SetTarget(reverse_e1, node_u);
// remove e2's (if bidir, otherwise only one) // remove e2's (if bidir, otherwise only one)
m_node_based_graph->DeleteEdge(v, forward_e2); m_node_based_graph->DeleteEdge(node_v, forward_e2);
m_node_based_graph->DeleteEdge(v, reverse_e2); m_node_based_graph->DeleteEdge(node_v, reverse_e2);
// update any involved turn restrictions // update any involved turn restrictions
m_restriction_map->FixupStartingTurnRestriction(u, v, w); m_restriction_map->FixupStartingTurnRestriction(node_u, node_v, node_w);
m_restriction_map->FixupArrivingTurnRestriction(u, v, w); m_restriction_map->FixupArrivingTurnRestriction(node_u, node_v, node_w);
m_restriction_map->FixupStartingTurnRestriction(w, v, u); m_restriction_map->FixupStartingTurnRestriction(node_w, node_v, node_u);
m_restriction_map->FixupArrivingTurnRestriction(w, v, u); m_restriction_map->FixupArrivingTurnRestriction(node_w, node_v, node_u);
// store compressed geometry in container // store compressed geometry in container
m_geometry_compressor.CompressEdge( m_geometry_compressor.CompressEdge(
forward_e1, forward_e1,
forward_e2, forward_e2,
v, node_v,
w, node_w,
forward_weight1 + forward_weight1 +
(add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty : 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, reverse_e2,
v, node_v,
u, node_u,
reverse_weight1, reverse_weight1,
reverse_weight2 + reverse_weight2 +
(add_traffic_signal_penalty ? speed_profile.trafficSignalPenalty : 0)); (add_traffic_signal_penalty ? speed_profile.traffic_signal_penalty : 0));
++removed_node_count; ++removed_node_count;
BOOST_ASSERT(m_node_based_graph->GetEdgeData(forward_e1).nameID == BOOST_ASSERT(m_node_based_graph->GetEdgeData(forward_e1).nameID ==
@ -478,21 +478,17 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
<< " many components"; << " many components";
SimpleLogger().Write() << "generating edge-expanded nodes"; SimpleLogger().Write() << "generating edge-expanded nodes";
Percent p(m_node_based_graph->GetNumberOfNodes()); Percent progress(m_node_based_graph->GetNumberOfNodes());
// loop over all edges and generate new set of nodes // loop over all edges and generate new set of nodes
for (NodeID u = 0, end = m_node_based_graph->GetNumberOfNodes(); u < end; ++u) for (NodeID u = 0, end = m_node_based_graph->GetNumberOfNodes(); u < end; ++u)
{ {
BOOST_ASSERT(u != SPECIAL_NODEID); BOOST_ASSERT(u != SPECIAL_NODEID);
BOOST_ASSERT(u < m_node_based_graph->GetNumberOfNodes()); BOOST_ASSERT(u < m_node_based_graph->GetNumberOfNodes());
p.printIncrement(); progress.printStatus(u);
for (EdgeID e1 : m_node_based_graph->GetAdjacentEdgeRange(u)) for (EdgeID e1 : m_node_based_graph->GetAdjacentEdgeRange(u))
{ {
const EdgeData &edge_data = m_node_based_graph->GetEdgeData(e1); const EdgeData &edge_data = m_node_based_graph->GetEdgeData(e1);
// if (edge_data.edgeBasedNodeID == SPECIAL_NODEID)
// {
// continue;
// }
BOOST_ASSERT(e1 != SPECIAL_EDGEID); BOOST_ASSERT(e1 != SPECIAL_EDGEID);
const NodeID v = m_node_based_graph->GetTarget(e1); const NodeID v = m_node_based_graph->GetTarget(e1);
@ -555,11 +551,12 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg
unsigned skipped_barrier_turns_counter = 0; unsigned skipped_barrier_turns_counter = 0;
unsigned compressed = 0; unsigned compressed = 0;
Percent p(m_node_based_graph->GetNumberOfNodes()); Percent progress(m_node_based_graph->GetNumberOfNodes());
for (NodeID u = 0, end = m_node_based_graph->GetNumberOfNodes(); u < end; ++u) for (NodeID u = 0, end = m_node_based_graph->GetNumberOfNodes(); u < end; ++u)
{ {
for (EdgeID e1 : m_node_based_graph->GetAdjacentEdgeRange(u)) progress.printStatus(u);
for (const EdgeID e1 : m_node_based_graph->GetAdjacentEdgeRange(u))
{ {
if (!m_node_based_graph->GetEdgeData(e1).forward) if (!m_node_based_graph->GetEdgeData(e1).forward)
{ {
@ -628,7 +625,7 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg
unsigned distance = edge_data1.distance; unsigned distance = edge_data1.distance;
if (m_traffic_lights.find(v) != m_traffic_lights.end()) if (m_traffic_lights.find(v) != m_traffic_lights.end())
{ {
distance += speed_profile.trafficSignalPenalty; distance += speed_profile.traffic_signal_penalty;
} }
const double angle = GetAngleBetweenThreeFixedPointCoordinates( const double angle = GetAngleBetweenThreeFixedPointCoordinates(
m_node_info_list[u], m_node_info_list[v], m_node_info_list[w]); m_node_info_list[u], m_node_info_list[v], m_node_info_list[w]);
@ -636,7 +633,7 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg
TurnInstruction turn_instruction = AnalyzeTurn(u, v, w, angle); TurnInstruction turn_instruction = AnalyzeTurn(u, v, w, angle);
if (turn_instruction == TurnInstruction::UTurn) if (turn_instruction == TurnInstruction::UTurn)
{ {
distance += speed_profile.uTurnPenalty; distance += speed_profile.u_turn_penalty;
} }
distance += turn_penalty; distance += turn_penalty;
@ -671,7 +668,6 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(const std::string &original_edg
false)); false));
} }
} }
p.printIncrement();
} }
FlushVectorToStream(edge_data_file, original_edge_data_vector); FlushVectorToStream(edge_data_file, original_edge_data_vector);
@ -705,19 +701,19 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co
return 0; return 0;
} }
TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID node_u,
const NodeID v, const NodeID node_v,
const NodeID w, const NodeID node_w,
double angle) const double angle)
const const
{ {
if (u == w) if (node_u == node_w)
{ {
return TurnInstruction::UTurn; return TurnInstruction::UTurn;
} }
const EdgeID edge1 = m_node_based_graph->FindEdge(u, v); const EdgeID edge1 = m_node_based_graph->FindEdge(node_u, node_v);
const EdgeID edge2 = m_node_based_graph->FindEdge(v, w); const EdgeID edge2 = m_node_based_graph->FindEdge(node_v, node_w);
const EdgeData &data1 = m_node_based_graph->GetEdgeData(edge1); const EdgeData &data1 = m_node_based_graph->GetEdgeData(edge1);
const EdgeData &data2 = m_node_based_graph->GetEdgeData(edge2); const EdgeData &data2 = m_node_based_graph->GetEdgeData(edge2);
@ -735,7 +731,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u,
if (data1.roundabout && data2.roundabout) if (data1.roundabout && data2.roundabout)
{ {
// Is a turn possible? If yes, we stay on the roundabout! // Is a turn possible? If yes, we stay on the roundabout!
if (1 == m_node_based_graph->GetDirectedOutDegree(v)) if (1 == m_node_based_graph->GetDirectedOutDegree(node_v))
{ {
// No turn possible. // No turn possible.
return TurnInstruction::NoTurn; return TurnInstruction::NoTurn;
@ -763,11 +759,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u,
{ {
// TODO: Here we should also do a small graph exploration to check for // TODO: Here we should also do a small graph exploration to check for
// more complex situations // more complex situations
if (0 != data1.nameID) if (0 != data1.nameID || m_node_based_graph->GetOutDegree(node_v) <= 2)
{
return TurnInstruction::NoTurn;
}
else if (m_node_based_graph->GetOutDegree(v) <= 2)
{ {
return TurnInstruction::NoTurn; return TurnInstruction::NoTurn;
} }

View File

@ -74,7 +74,7 @@ class EdgeBasedGraphFactory
void GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes); void GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes);
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, double angle) const; TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, const double angle) const;
int GetTurnPenalty(double angle, lua_State *lua_state) const; int GetTurnPenalty(double angle, lua_State *lua_state) const;
@ -83,12 +83,12 @@ class EdgeBasedGraphFactory
struct SpeedProfileProperties struct SpeedProfileProperties
{ {
SpeedProfileProperties() SpeedProfileProperties()
: trafficSignalPenalty(0), uTurnPenalty(0), has_turn_penalty_function(false) : traffic_signal_penalty(0), u_turn_penalty(0), has_turn_penalty_function(false)
{ {
} }
int trafficSignalPenalty; int traffic_signal_penalty;
int uTurnPenalty; int u_turn_penalty;
bool has_turn_penalty_function; bool has_turn_penalty_function;
} speed_profile; } speed_profile;
@ -120,7 +120,7 @@ class EdgeBasedGraphFactory
void FlushVectorToStream(std::ofstream &edge_data_file, void FlushVectorToStream(std::ofstream &edge_data_file,
std::vector<OriginalEdgeData> &original_edge_data_vector) const; std::vector<OriginalEdgeData> &original_edge_data_vector) const;
unsigned max_id; NodeID max_id;
}; };
#endif /* EDGEBASEDGRAPHFACTORY_H_ */ #endif /* EDGEBASEDGRAPHFACTORY_H_ */

View File

@ -463,9 +463,9 @@ Prepare::SetupScriptingEnvironment(lua_State *lua_state,
std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl; std::cerr << lua_tostring(lua_state, -1) << " occured in scripting block" << std::endl;
return false; return false;
} }
speed_profile.trafficSignalPenalty = 10 * lua_tointeger(lua_state, -1); speed_profile.traffic_signal_penalty = 10 * lua_tointeger(lua_state, -1);
SimpleLogger().Write(logDEBUG) SimpleLogger().Write(logDEBUG)
<< "traffic_signal_penalty: " << speed_profile.trafficSignalPenalty; << "traffic_signal_penalty: " << speed_profile.traffic_signal_penalty;
if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n")) if (0 != luaL_dostring(lua_state, "return u_turn_penalty\n"))
{ {
@ -473,7 +473,7 @@ Prepare::SetupScriptingEnvironment(lua_State *lua_state,
return false; return false;
} }
speed_profile.uTurnPenalty = 10 * lua_tointeger(lua_state, -1); speed_profile.u_turn_penalty = 10 * lua_tointeger(lua_state, -1);
speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function"); speed_profile.has_turn_penalty_function = lua_function_exists(lua_state, "turn_function");
return true; return true;