I have an undirected boost::adjacency_graph. Given a vertex, I want to find all the pair of edges for which the vertex is the source.
As an example, if I have
0 --- 1 --- 2
the pairs for 0 and 2 will be the empty set and for 1 will be ((1,0), (1,2))
for
0 --- 1 --- 2
\--- 3
the pairs for 0, 2 and 3 will the empty set, while for 1 will be
((1,0), (1,2))
((1,0), (1,3))
((1,2), (1,3))
I was thinking about something like
std::vector<std::pair<edge, edge> edges;
for (const auto vertex : boost::make_iterator_range(boost::vertices(graph))) {
for (const auto outEdge1 : boost::make_iterator_range(boost::out_edges(vertex, graph))) {
for (const auto outEdge2 : boost::make_iterator_range(boost::out_edges(vertex, graph))) {
if (outEdge != outEdge2) edges.push_back(outEdge1, outEdge2);
}
}
}
but this will fail, as it will add for example ((1,0), (1, 2))
and ((1,2), (1, 0))
How can I avoid that? I think this is just the combinations without repetition of the out edges for the vertex
Given the out edges
(1,0)
(1,2)
(1,3)
How can I get the combinations?