I find graph-tool documentation extremely obscure and much more cryptic than other analogous libraries.
I really can't figure out how to "extract" components (aka connected components) from a graph in graph-tools. I would like to save subgraphs in separate files as separate Graphs but I don't understand how to identify them starting from my Graph object.
Definition: A graph whose vertices and edges are subsets of another graph.
A subgraph H = (V ,E ) of a graph G = (V,E) is a pair V ⊆ V and E ⊆ E. We say that H is an induced subgraph of G if all the edges between the vertices in V from E are in E . Example Figure 4 shows two subgraphs of G1. The first subgraph is an induced subgraph.
A subgraph extracts data from a blockchain, processing it and storing it so that it can be easily queried via GraphQL. The subgraph definition consists of a few files: subgraph. yaml : a YAML file containing the subgraph manifest.
The simplest (and fastest) way to do this is to do use a GraphView object.
# label the components in a property map
c = label_components(g)[0]
# "extract" component number 3
u = GraphView(g, vfilt=c.a == 3)
The object u
is now an induced subgraph of g
that contains all the vertices of the component label 3. Note that a GraphView
object does not copy the graph, it simply masks out the other vertices/edges.
If you wish a copy of the subgraph (e.g. if you want to modify it, or the original graph), you just instantiate a new Graph
object from it:
u = Graph(u, prune=True)
More information on graph views is available in the documentation: https://graph-tool.skewed.de/static/doc/quickstart.html#graph-views
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With