I need to process a lot of sub-graphs of given graph G. Using for that purpose graph-tool seems to be nice approach with utilizing its functionality of GraphViews and edge/vertex filtering functionality. To save time I would like to cache information about already processed sub-graphs. I thought that the fastest way would be compare vertex and edge filters. Such operation would be quite fast but... It seems that we can end up with the same sub-graph with different filters.
For example initial graph looks like:
After running such code:
vFilter1=g.new_vertex_property("bool", val=True)
eFilter1=g.new_edge_property("bool", val=True)
vFilter1[g.vertex(3)]=False
eFilter1[g.edge(1, 2)]=False
f1=gt.GraphView(g, efilt=eFilter1, vfilt=vFilter1)
print ("VERTEX filter:", f1.get_vertex_filter()[0].get_array())
print ("EDGE filter:", f1.get_edge_filter()[0].get_array())
We will have filters like:
VERTEX filter: [1 1 1 0]
EDGE filter: [1 0 1 1 1]
After a little bit different filtering:
vFilter2=g.new_vertex_property("bool", val=True)
eFilter2=g.new_edge_property("bool", val=True)
vFilter2[g.vertex(3)]=False
eFilter2[g.edge(1, 2)]=False
eFilter2[g.edge(0, 3)]=False
eFilter2[g.edge(2, 3)]=False
f2=gt.GraphView(g, efilt=eFilter2, vfilt=vFilter2)
print ("VERTEX filter:", f2.get_vertex_filter()[0].get_array())
print ("EDGE filter:", f2.get_edge_filter()[0].get_array())
Filters will look like this:
VERTEX filter: [1 1 1 0]
EDGE filter: [1 0 0 0 1]
Both created sub-graphs look like this:
Running algorithm on quite large graphs may filter out edges/vertices in different order and it may lead to have same sub-graphs but with different filter setup. Is there any nice method of doing comparison of such views? (Hopefully done by C++ layer of graph-tool)
If the vertices of the subgraphs are aligned, you may use the similarity()
function. Otherwise, you have to resort to isomorphism()
.