11#include <boost/graph/connected_components.hpp>
12#include <boost/graph/strong_components.hpp>
20template <
typename GraphWrapper>
28[[deprecated(
"Use G.connected_component_groups() instead.")]]
30 return G.connected_component_groups();
33template <
typename GraphWrapper>
40[[deprecated(
"Use G.connected_components() instead.")]]
42 return G.connected_components();
45template <
typename GraphWrapper>
53[[deprecated(
"Use G.strongly_connected_component_groups() instead.")]]
55 return G.strongly_connected_component_groups();
58template <
typename GraphWrapper>
66[[deprecated(
"Use G.strong_component_map() instead.")]]
68 return G.strong_component_map();
71template <
typename GraphWrapper>
78[[deprecated(
"Use G.strong_components() instead.")]]
80 return G.strong_components();
83template <
typename GraphWrapper>
91[[deprecated(
"Use G.connected_component_map() instead.")]]
93 return G.connected_component_map();
96template <
typename GraphWrapper>
104[[deprecated(
"Use G.strongly_connected_components() instead.")]]
106 return G.strongly_connected_components();
109template <
typename GraphWrapper>
117[[deprecated(
"Use G.strongly_connected_component_map() instead.")]]
119 return G.strongly_connected_component_map();
122template <
typename GraphWrapper>
130[[deprecated(
"Use G.strongly_connected_component_roots() instead.")]]
132 return G.strongly_connected_component_roots();
135template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
137 const int n =
static_cast<int>(boost::num_vertices(g));
138 std::vector<int> comp(n);
139 std::vector<boost::default_color_type> color(n);
140 const int num = boost::connected_components(
142 boost::make_iterator_property_map(comp.begin(), vertex_index_map),
143 boost::color_map(boost::make_iterator_property_map(color.begin(), vertex_index_map))
144 .vertex_index_map(vertex_index_map)
146 std::vector<std::vector<NodeID>> components(num);
147 for (
auto [v, vend] = boost::vertices(g); v != vend; ++v) {
148 const auto index =
static_cast<int>(get_vertex_index(*v));
149 components[comp[index]].push_back(get_node_id(*v));
154template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
156 const int n =
static_cast<int>(boost::num_vertices(g));
157 std::vector<int> comp(n);
158 std::vector<boost::default_color_type> color(n);
159 boost::connected_components(
161 boost::make_iterator_property_map(comp.begin(), vertex_index_map),
162 boost::color_map(boost::make_iterator_property_map(color.begin(), vertex_index_map))
163 .vertex_index_map(vertex_index_map)
165 return build_node_indexed_result<int>([&](VertexDesc v) {
166 return comp[get_vertex_index(v)];
170template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
172 const int n =
static_cast<int>(boost::num_vertices(g));
173 std::vector<int> comp(n);
174 std::vector<boost::default_color_type> color(n);
175 const int num = boost::strong_components(
177 boost::make_iterator_property_map(comp.begin(), vertex_index_map),
178 boost::color_map(boost::make_iterator_property_map(color.begin(), vertex_index_map))
179 .vertex_index_map(vertex_index_map)
181 std::vector<std::vector<NodeID>> components(num);
182 for (
auto [v, vend] = boost::vertices(g); v != vend; ++v) {
183 const auto index =
static_cast<int>(get_vertex_index(*v));
184 components[comp[index]].push_back(get_node_id(*v));
189template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
191 const int n =
static_cast<int>(boost::num_vertices(g));
192 std::vector<int> comp(n);
193 std::vector<boost::default_color_type> color(n);
194 boost::strong_components(
196 boost::make_iterator_property_map(comp.begin(), vertex_index_map),
197 boost::color_map(boost::make_iterator_property_map(color.begin(), vertex_index_map))
198 .vertex_index_map(vertex_index_map)
200 return build_node_indexed_result<int>([&](VertexDesc v) {
201 return comp[get_vertex_index(v)];
205template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
207 const int n =
static_cast<int>(boost::num_vertices(g));
208 std::vector<int> comp(n);
209 std::vector<VertexDesc> roots(n);
210 std::vector<boost::default_color_type> color(n);
211 boost::strong_components(
213 boost::make_iterator_property_map(comp.begin(), vertex_index_map),
214 boost::root_map(boost::make_iterator_property_map(roots.begin(), vertex_index_map))
215 .color_map(boost::make_iterator_property_map(color.begin(), vertex_index_map))
216 .vertex_index_map(vertex_index_map)
218 return build_node_indexed_result<NodeID>([&](VertexDesc v) {
219 return get_node_id(roots[get_vertex_index(v)]);
223template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
226template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
229template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
232template <
typename NodeID,
typename EdgeWeight,
bool Directed,
bool Multi,
bool Weighted,
typename OutEdgeSelector,
typename VertexSelector>
auto strongly_connected_component_roots() const
Returns one representative root node for each strong component.
Definition components.hpp:233
auto strongly_connected_component_map() const
Alias for strong_component_map().
Definition components.hpp:230
auto connected_component_groups() const
Groups each connected component as a vector of node IDs.
Definition components.hpp:136
auto connected_component_map() const
Returns the connected-component index assigned to each node.
Definition components.hpp:224
auto strong_component_map() const
Returns the component index assigned to each node in a directed graph.
Definition components.hpp:190
auto strong_components() const
Returns the number of strongly connected components in a directed graph.
Definition components.hpp:206
auto connected_components() const
Returns the number of connected components in an undirected graph.
Definition components.hpp:155
auto strongly_connected_component_groups() const
Groups each strongly connected component as a vector of node IDs.
Definition components.hpp:171
auto strongly_connected_components() const
Alias for strongly_connected_component_groups().
Definition components.hpp:227
auto strongly_connected_component_map(const GraphWrapper &G)
Deprecated free-function alias for G.strongly_connected_component_map().
Definition components.hpp:118
auto strongly_connected_component_roots(const GraphWrapper &G)
Deprecated free-function alias for G.strongly_connected_component_roots().
Definition components.hpp:131
auto strongly_connected_components(const GraphWrapper &G)
Deprecated free-function alias for G.strongly_connected_components().
Definition components.hpp:105
auto connected_component_groups(const GraphWrapper &G)
Deprecated free-function alias for G.connected_component_groups().
Definition components.hpp:29
auto strong_components(const GraphWrapper &G)
Deprecated free-function alias for G.strong_components().
Definition components.hpp:79
auto strong_component_map(const GraphWrapper &G)
Deprecated free-function alias for G.strong_component_map().
Definition components.hpp:67
auto connected_component_map(const GraphWrapper &G)
Deprecated free-function alias for G.connected_component_map().
Definition components.hpp:92
auto connected_components(const GraphWrapper &G)
Deprecated free-function alias for G.connected_components().
Definition components.hpp:41
auto strongly_connected_component_groups(const GraphWrapper &G)
Deprecated free-function alias for G.strongly_connected_component_groups().
Definition components.hpp:54
Core graph wrapper, proxy surface, and public alias presets.