Apply clang-format on BFSComponentExplorer and RestrictionMap

This commit is contained in:
Patrick Niklaus
2014-05-08 23:29:24 +02:00
parent 22d0861f6d
commit e00ef38305
4 changed files with 194 additions and 193 deletions
+48 -44
View File
@@ -4,35 +4,39 @@
#include "DynamicGraph.h"
#include "ImportEdge.h"
struct NodeBasedEdgeData {
NodeBasedEdgeData() : distance(INVALID_EDGE_WEIGHT), edgeBasedNodeID(SPECIAL_NODEID), nameID(std::numeric_limits<unsigned>::max()),
type(std::numeric_limits<short>::max()), isAccessRestricted(false), shortcut(false), forward(false), backward(false),
roundabout(false), ignore_in_grid(false), contraFlow(false)
{ }
struct NodeBasedEdgeData
{
NodeBasedEdgeData()
: distance(INVALID_EDGE_WEIGHT), edgeBasedNodeID(SPECIAL_NODEID),
nameID(std::numeric_limits<unsigned>::max()), type(std::numeric_limits<short>::max()),
isAccessRestricted(false), shortcut(false), forward(false), backward(false),
roundabout(false), ignore_in_grid(false), contraFlow(false)
{
}
int distance;
unsigned edgeBasedNodeID;
unsigned nameID;
short type;
bool isAccessRestricted:1;
bool shortcut:1;
bool forward:1;
bool backward:1;
bool roundabout:1;
bool ignore_in_grid:1;
bool contraFlow:1;
bool isAccessRestricted : 1;
bool shortcut : 1;
bool forward : 1;
bool backward : 1;
bool roundabout : 1;
bool ignore_in_grid : 1;
bool contraFlow : 1;
void SwapDirectionFlags() {
void SwapDirectionFlags()
{
bool temp_flag = forward;
forward = backward;
backward = temp_flag;
}
bool IsEqualTo( const NodeBasedEdgeData & other ) const {
return (forward == other.forward) &&
(backward == other.backward) &&
(nameID == other.nameID) &&
(ignore_in_grid == other.ignore_in_grid) &&
bool IsEqualTo(const NodeBasedEdgeData &other) const
{
return (forward == other.forward) && (backward == other.backward) &&
(nameID == other.nameID) && (ignore_in_grid == other.ignore_in_grid) &&
(contraFlow == other.contraFlow);
}
};
@@ -40,37 +44,41 @@ struct NodeBasedEdgeData {
typedef DynamicGraph<NodeBasedEdgeData> NodeBasedDynamicGraph;
// Factory method to create NodeBasedDynamicGraph from ImportEdges
inline std::shared_ptr<NodeBasedDynamicGraph> NodeBasedDynamicGraphFromImportEdges(
int number_of_nodes,
std::vector<ImportEdge>& input_edge_list
) {
inline std::shared_ptr<NodeBasedDynamicGraph>
NodeBasedDynamicGraphFromImportEdges(int number_of_nodes, std::vector<ImportEdge> &input_edge_list)
{
typedef NodeBasedDynamicGraph::InputEdge DynInputEdge;
std::sort( input_edge_list.begin(), input_edge_list.end() );
std::sort(input_edge_list.begin(), input_edge_list.end());
//TODO: remove duplicate edges
// TODO: remove duplicate edges
DeallocatingVector<DynInputEdge> edges_list;
DynInputEdge edge;
for(const ImportEdge& import_edge : input_edge_list) {
for (const ImportEdge &import_edge : input_edge_list)
{
if( !import_edge.isForward() ) {
if (!import_edge.isForward())
{
edge.source = import_edge.target();
edge.target = import_edge.source();
edge.data.backward = import_edge.isForward();
edge.data.forward = import_edge.isBackward();
} else {
}
else
{
edge.source = import_edge.source();
edge.target = import_edge.target();
edge.data.forward = import_edge.isForward();
edge.data.backward = import_edge.isBackward();
}
if( edge.source == edge.target ) {
if (edge.source == edge.target)
{
continue;
}
edge.data.distance = (std::max)((int)import_edge.weight(), 1 );
BOOST_ASSERT( edge.data.distance > 0 );
edge.data.distance = (std::max)((int)import_edge.weight(), 1);
BOOST_ASSERT(edge.data.distance > 0);
edge.data.shortcut = false;
edge.data.roundabout = import_edge.isRoundabout();
edge.data.ignore_in_grid = import_edge.ignoreInGrid();
@@ -78,29 +86,25 @@ inline std::shared_ptr<NodeBasedDynamicGraph> NodeBasedDynamicGraphFromImportEdg
edge.data.type = import_edge.type();
edge.data.isAccessRestricted = import_edge.isAccessRestricted();
edge.data.contraFlow = import_edge.isContraFlow();
edges_list.push_back( edge );
edges_list.push_back(edge);
if( !import_edge.IsSplit() ) {
using std::swap; //enable ADL
swap( edge.source, edge.target );
if (!import_edge.IsSplit())
{
using std::swap; // enable ADL
swap(edge.source, edge.target);
edge.data.SwapDirectionFlags();
edges_list.push_back( edge );
edges_list.push_back(edge);
}
}
std::sort( edges_list.begin(), edges_list.end() );
auto graph = std::make_shared<NodeBasedDynamicGraph>(
number_of_nodes,
edges_list
);
std::sort(edges_list.begin(), edges_list.end());
auto graph = std::make_shared<NodeBasedDynamicGraph>(number_of_nodes, edges_list);
//FIXME probably unneeded since this is the end of scope
// FIXME probably unneeded since this is the end of scope
DeallocatingVector<DynInputEdge>().swap(edges_list);
BOOST_ASSERT(0 == edges_list.size() );
BOOST_ASSERT(0 == edges_list.size());
return graph;
}
#endif
+78 -75
View File
@@ -1,36 +1,42 @@
#include "RestrictionMap.h"
#include "NodeBasedGraph.h"
RestrictionMap::RestrictionMap(const std::shared_ptr<NodeBasedDynamicGraph>& graph, const std::vector<TurnRestriction> & input_restrictions_list)
: m_count(0)
, m_graph(graph)
RestrictionMap::RestrictionMap(const std::shared_ptr<NodeBasedDynamicGraph> &graph,
const std::vector<TurnRestriction> &input_restrictions_list)
: m_count(0), m_graph(graph)
{
// decompose restirction consisting of a start, via and end note into a start-edge
// and all end-nodes
for (auto& restriction : input_restrictions_list) {
for (auto &restriction : input_restrictions_list)
{
std::pair<NodeID, NodeID> restriction_source =
std::make_pair(restriction.fromNode, restriction.viaNode);
unsigned index;
auto restriction_iter = m_restriction_map.find(restriction_source);
if(restriction_iter == m_restriction_map.end()) {
if (restriction_iter == m_restriction_map.end())
{
index = m_restriction_bucket_list.size();
m_restriction_bucket_list.resize(index+1);
m_restriction_bucket_list.resize(index + 1);
m_restriction_map.emplace(restriction_source, index);
} else {
}
else
{
index = restriction_iter->second;
//Map already contains an is_only_*-restriction
if(m_restriction_bucket_list.at(index).begin()->second) {
// Map already contains an is_only_*-restriction
if (m_restriction_bucket_list.at(index).begin()->second)
{
continue;
} else if(restriction.flags.isOnly) {
//We are going to insert an is_only_*-restriction. There can be only one.
}
else if (restriction.flags.isOnly)
{
// We are going to insert an is_only_*-restriction. There can be only one.
m_count -= m_restriction_bucket_list.at(index).size();
m_restriction_bucket_list.at(index).clear();
}
}
++m_count;
m_restriction_bucket_list.at(index).push_back(
std::make_pair( restriction.toNode, restriction.flags.isOnly)
);
m_restriction_bucket_list.at(index)
.push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly));
}
}
@@ -39,41 +45,40 @@ RestrictionMap::RestrictionMap(const std::shared_ptr<NodeBasedDynamicGraph>& gra
*
* Note: We need access to node based graph.
*/
void RestrictionMap::FixupArrivingTurnRestriction(
const NodeID u,
const NodeID v,
const NodeID w
) {
BOOST_ASSERT( u != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( v != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( w != std::numeric_limits<unsigned>::max() );
void RestrictionMap::FixupArrivingTurnRestriction(const NodeID u, const NodeID v, const NodeID w)
{
BOOST_ASSERT(u != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(v != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(w != std::numeric_limits<unsigned>::max());
// find all possible start edges
// it is more efficent to get a (small) list of potential start edges
// than iterating over all buckets
std::vector<NodeID> predecessors;
for(
EdgeID current_edge_id = m_graph->BeginEdges(u);
current_edge_id < m_graph->EndEdges(u);
++current_edge_id
) {
const EdgeData & edge_data = m_graph->GetEdgeData(current_edge_id);
for (EdgeID current_edge_id = m_graph->BeginEdges(u); current_edge_id < m_graph->EndEdges(u);
++current_edge_id)
{
const EdgeData &edge_data = m_graph->GetEdgeData(current_edge_id);
const NodeID target = m_graph->GetTarget(current_edge_id);
if( edge_data.backward && ( v != target) ) {
if (edge_data.backward && (v != target))
{
predecessors.push_back(target);
}
}
for(const NodeID x : predecessors) {
const std::pair<NodeID, NodeID> restr_start = std::make_pair(x,u);
auto restriction_iterator = m_restriction_map.find( restr_start );
if( restriction_iterator == m_restriction_map.end() )
for (const NodeID x : predecessors)
{
const std::pair<NodeID, NodeID> restr_start = std::make_pair(x, u);
auto restriction_iterator = m_restriction_map.find(restr_start);
if (restriction_iterator == m_restriction_map.end())
continue;
const unsigned index = restriction_iterator->second;
auto& bucket = m_restriction_bucket_list.at(index);
for(RestrictionTarget& restriction_target : bucket) {
if( v == restriction_target.first ) {
auto &bucket = m_restriction_bucket_list.at(index);
for (RestrictionTarget &restriction_target : bucket)
{
if (v == restriction_target.first)
{
restriction_target.first = w;
}
}
@@ -83,26 +88,24 @@ void RestrictionMap::FixupArrivingTurnRestriction(
/**
* Replaces the start edge (v, w) with (u, w), only start node changes.
*/
void RestrictionMap::FixupStartingTurnRestriction(
const NodeID u,
const NodeID v,
const NodeID w
) {
BOOST_ASSERT( u != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( v != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( w != std::numeric_limits<unsigned>::max() );
void RestrictionMap::FixupStartingTurnRestriction(const NodeID u, const NodeID v, const NodeID w)
{
BOOST_ASSERT(u != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(v != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(w != std::numeric_limits<unsigned>::max());
const std::pair<NodeID, NodeID> old_start = std::make_pair(v,w);
const std::pair<NodeID, NodeID> old_start = std::make_pair(v, w);
auto restriction_iterator = m_restriction_map.find( old_start );
if( restriction_iterator != m_restriction_map.end() ) {
auto restriction_iterator = m_restriction_map.find(old_start);
if (restriction_iterator != m_restriction_map.end())
{
const unsigned index = restriction_iterator->second;
// remove old restriction start (v,w)
m_restriction_map.erase( restriction_iterator );
m_restriction_map.erase(restriction_iterator);
// insert new restriction start (u,w) (point to index)
const std::pair<NodeID, NodeID> new_start = std::make_pair(u,w);
m_restriction_map.insert( std::make_pair(new_start, index) );
const std::pair<NodeID, NodeID> new_start = std::make_pair(u, w);
m_restriction_map.insert(std::make_pair(new_start, index));
}
}
@@ -110,21 +113,22 @@ void RestrictionMap::FixupStartingTurnRestriction(
* Check if the edge (u, v) is contained in any turn restriction.
* If so returns id of first target node.
*/
NodeID RestrictionMap::CheckForEmanatingIsOnlyTurn(
const NodeID u,
const NodeID v
) const {
BOOST_ASSERT( u != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( v != std::numeric_limits<unsigned>::max() );
NodeID RestrictionMap::CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const
{
BOOST_ASSERT(u != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(v != std::numeric_limits<unsigned>::max());
const std::pair<NodeID, NodeID> restriction_source = std::make_pair(u, v);
auto restriction_iter = m_restriction_map.find(restriction_source);
if (restriction_iter != m_restriction_map.end()) {
if (restriction_iter != m_restriction_map.end())
{
const unsigned index = restriction_iter->second;
auto& bucket = m_restriction_bucket_list.at(index);
for(const RestrictionSource& restriction_target : bucket) {
if(restriction_target.second) {
auto &bucket = m_restriction_bucket_list.at(index);
for (const RestrictionSource &restriction_target : bucket)
{
if (restriction_target.second)
{
return restriction_target.first;
}
}
@@ -136,26 +140,25 @@ NodeID RestrictionMap::CheckForEmanatingIsOnlyTurn(
/**
* Checks if the turn described by start u, via v and targed w is covert by any turn restriction.
*/
bool RestrictionMap::CheckIfTurnIsRestricted(
const NodeID u,
const NodeID v,
const NodeID w
) const {
BOOST_ASSERT( u != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( v != std::numeric_limits<unsigned>::max() );
BOOST_ASSERT( w != std::numeric_limits<unsigned>::max() );
bool RestrictionMap::CheckIfTurnIsRestricted(const NodeID u, const NodeID v, const NodeID w) const
{
BOOST_ASSERT(u != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(v != std::numeric_limits<unsigned>::max());
BOOST_ASSERT(w != std::numeric_limits<unsigned>::max());
const std::pair<NodeID, NodeID> restriction_source = std::make_pair(u, v);
auto restriction_iter = m_restriction_map.find(restriction_source);
if (restriction_iter != m_restriction_map.end()) {
if (restriction_iter != m_restriction_map.end())
{
const unsigned index = restriction_iter->second;
auto& bucket = m_restriction_bucket_list.at(index);
for(const RestrictionTarget & restriction_target : bucket) {
if(
( w == restriction_target.first ) && // target found
( !restriction_target.second ) // and not an only_-restr.
) {
auto &bucket = m_restriction_bucket_list.at(index);
for (const RestrictionTarget &restriction_target : bucket)
{
if ((w == restriction_target.first) && // target found
(!restriction_target.second) // and not an only_-restr.
)
{
return true;
}
}
+11 -11
View File
@@ -43,9 +43,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
class RestrictionMap
{
public:
RestrictionMap(const std::shared_ptr<NodeBasedDynamicGraph>& graph,
const std::vector<TurnRestriction> & input_restrictions_list);
public:
RestrictionMap(const std::shared_ptr<NodeBasedDynamicGraph> &graph,
const std::vector<TurnRestriction> &input_restrictions_list);
void FixupArrivingTurnRestriction(const NodeID u, const NodeID v, const NodeID w);
void FixupStartingTurnRestriction(const NodeID u, const NodeID v, const NodeID w);
@@ -54,16 +54,16 @@ public:
unsigned size() { return m_count; }
private:
typedef std::pair<NodeID, NodeID> RestrictionSource;
typedef std::pair<NodeID, bool> RestrictionTarget;
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
typedef NodeBasedDynamicGraph::EdgeData EdgeData;
private:
typedef std::pair<NodeID, NodeID> RestrictionSource;
typedef std::pair<NodeID, bool> RestrictionTarget;
typedef std::vector<RestrictionTarget> EmanatingRestrictionsVector;
typedef NodeBasedDynamicGraph::EdgeData EdgeData;
unsigned m_count;
std::shared_ptr<NodeBasedDynamicGraph> m_graph;
unsigned m_count;
std::shared_ptr<NodeBasedDynamicGraph> m_graph;
//! index -> list of (target, isOnly)
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
std::vector<EmanatingRestrictionsVector> m_restriction_bucket_list;
//! maps (start, via) -> bucket index
boost::unordered_map<RestrictionSource, unsigned> m_restriction_map;
};