BGL : How do I get a list of subgraphs, given a graph? - boost-graph

I have a boost adjacency_list, which is my main graph. To this graph, I added some subgraphs using the create_subgraph function.
My question is, how can I get the list of subgraphs I just created without storing the Graph objects?
eg:
Graph g; // typedef for a adj. list
Graph sub_graph1 = g.create_subgraph()
Graph sub_graph2 = g.create_subgraph()
//Do some processing here
//Find all subgraphs of g - iterator/array
Graph all_subgraphs[] = g.???
Is there any such function which will get me all the subgraphs of the graph g?

Have a look at the connected_components function. If your subgraphs are disjoint then the number of connected compontns is the number of subgraphs in your graph. Furthermore you can get a component map, i.e. a subgraph index for each graph vertex, from the function.

Related

Should I use filtered graph or subgraph or something else?

I am using BGL recently, and I have a graph G now. I need a data structure that can rule out one vertex at a time, without breaking the original graph. What should I do?
At first I found the filtered graph, but I need to label all vertices, and create a new filtered graph after I rule out a vertex. If I have N vertices in the graph, I need to filter N times.
I also thought of a subgraph, but it doesn't support removing vertices.
You can use a filtered graph.
You can have a dynamic filter predicate that incrementally filters out more vertices. No need to create more filtered graphs at all.
See an example:
Using two objects as hash key for an unordered_map or alternatives
boost graph copy and removing vertex
Remove 100,000+ nodes from a Boost graph

Graph Theory: function for a DAG?

For a directed acyclic graph where vertices have numerical labels what is the best way to return the maximum label on a vertex reachable from vertex u (including u itself)? Ideally it should run in time linear in the size of the graph.

How to direct an edge in OGDF?

I have a simple UNDIRECTED Graph G, and want to reverse an edge if a certain condition is true.
The following code gives an error that the EdgeElement constructor is inaccessible:
if(dfsNum[source->index()]>dfsNum[target->index()]){
EdgeElement ee(target, source, target->firstAdj(), source->firstAdj(), e->index());
e = ee.theEdge();
}
Is this the correct way of doing what I am doing?
IMPORTANT EDIT:
My bad. I do not have to reverse the edge, I have to direct it.
Based on the documentation, you can delete an edge using delEdge and add a new edge using newEdge. The undirected graph may really be a directional graph with two directed edges for every undirected edge. If that is the case, delete the edge that you do not need anymore. For example, to direct an undirected edge (u, v) from u to v, delete the directed edge (v, u), so the only remaining directed edge is (u, v). You can find an edge to delete using the searchEdge method.
G.reverseEdge(e) reverses edge e in graph G.

topological sort on boost graph for vertices that are connected through a given vertex only

I have a large graph which represents a set of dependencies.
A -->B
A -->C
B -->F
C -->G
D -->E
E -->L
F -->H
F -->I
H -->K
J -->K
Given B as a starting node, result needs to be : B F I H K
I do not need any other nodes since they cannot be reached from B.
A user can specify a node and I need to collect all the paths and the nodes in those paths and print the topological sort of those nodes.
Currently I am implementing this by
Create a new graph
Extract all the outgoing edges from the given node.
Add those edges in a graph. From those edges, get the nodes and also add them to the new graph.
For each node in step 3, repeat (2) and (3)
On that new graph, perform a topological sort and get the order of the nodes
Is there any other better way to do this or known algorithm for finding the topological sort of a subset of nodes?
I would look into the depth_first_visit() function, and the Visitor Pattern provided by boost. The Visitor Pattern allows you to inspect vertices and edges as the tree is searched. The depth_first_visit() function allows you to start a DFS search starting at a specific vertex.

boost graph adjacency_list, retrieving a node's parents

I want to find in an adjacency graph from the bgl how give a Vertexdescriptor and get the set of nodes that are parents of this given node.
i would like to do this in directed graph, it seems you could use a bidirectional graph but i want to be able to restrict it so that there are no cycles.
The bidirectional graph is not an undirected graph: it's a directed graph that simply stores the information on inbound arcs. It seems just right the info you want.