2 #ifndef ANDRES_GRAPH_COMPONENTS_HXX
3 #define ANDRES_GRAPH_COMPONENTS_HXX
10 #include "andres/partition.hxx"
12 #include "subgraph.hxx"
24 template<
class SUBGRAPH_MASK>
25 std::size_t
build(
const Graph&,
const SUBGRAPH_MASK&);
26 bool areConnected(
const std::size_t,
const std::size_t)
const;
38 template<
class SUBGRAPH_MASK>
39 std::size_t
build(
const Graph&,
const SUBGRAPH_MASK&);
40 bool areConnected(
const std::size_t,
const std::size_t)
const;
52 template<
class GRAPH,
class ITERATOR>
69 template<
class GRAPH,
class SUBGRAPH_MASK,
class ITERATOR>
73 const SUBGRAPH_MASK& mask,
76 std::size_t label = 0;
77 std::vector<bool> visited(graph.numberOfVertices(),
false);
78 std::queue<std::size_t> queue;
79 for(std::size_t v = 0; v < graph.numberOfVertices(); ++v) {
85 while(!queue.empty()) {
86 std::size_t w = queue.front();
88 for(
typename GRAPH::AdjacencyIterator it = graph.adjacenciesFromVertexBegin(w);
89 it != graph.adjacenciesFromVertexEnd(w); ++it) {
90 if(mask.edge(it->edge())
91 && mask.vertex(it->vertex())
92 && !visited[it->vertex()]) {
93 labeling[it->vertex()] = label;
94 queue.push(it->vertex());
95 visited[it->vertex()] =
true;
109 template<
class GRAPH>
115 template<
class GRAPH>
123 template<
class GRAPH>
124 template<
class SUBGRAPH_MASK>
128 const SUBGRAPH_MASK& mask
130 labels_.resize(graph.numberOfVertices());
134 template<
class GRAPH>
137 const std::size_t vertex0,
138 const std::size_t vertex1
140 return labels_[vertex0] == labels_[vertex1];
143 template<
class GRAPH>
149 template<
class GRAPH>
157 template<
class GRAPH>
158 template<
class SUBGRAPH_MASK>
162 const SUBGRAPH_MASK& mask
164 partition_.assign(graph.numberOfVertices());
165 for(std::size_t edge = 0; edge < graph.numberOfEdges(); ++edge) {
166 if(mask.edge(edge)) {
167 const std::size_t v0 = graph.vertexOfEdge(edge, 0);
168 const std::size_t v1 = graph.vertexOfEdge(edge, 1);
169 if(mask.vertex(v0) && mask.vertex(v1)) {
170 partition_.merge(v0, v1);
174 return partition_.numberOfSets();
177 template<
class GRAPH>
180 const std::size_t vertex0,
181 const std::size_t vertex1
183 return partition_.find(vertex0) == partition_.find(vertex1);
189 #endif // #ifndef ANDRES_GRAPH_COMPONENTS_HXX