Hi group,
I have two questions with relation to this title:
1. I have AdjGraph class as following:
class AdjGraph(nx.Graph):def __init__(self):
super(AdjGraph,self).__init__()
self.ax=None
self._nodesize=30
self._pos={}
and I have object adj1, adj2 of class AdjGraph,
then I want to use
import networkx.algorithms.isomorphism as iso
em=***
GM=iso.GraphMatcher(adj1,adj2,edge_match=em)
print GM
2.Does networkx 1.7 support weighted subgraph monomorphism,
and how to use it?
def my_edge_match(data1, data2):
if data1==data2:
return True
else:
return False
# if 'weight' in data1:
# if 'weight' in data2:
# return data1['weight']==data2['weight']
# else:
# return False
# else:
# return True
def test():
G1=nx.Graph()
G1.add_cycle(['a','b','c','d'])
G1.edge['a']['b']['weight'] = "red"
G2=nx.Graph()
G2.add_cycle([0,1,2,3])
G2.edge[1][2]['weight'] = "red"
em=iso.generic_edge_match("weight","2",my_edge_match)
GM = iso.GraphMatcher(G1,G2,edge_match=em)
if GM.subgraph_is_isomorphic()==True:
sub= GM.subgraph_isomorphisms_iter()
for s in sub:
print s
if __name__=="__main__":
test()
G=nx.Graph()
G.add_path(['a','b','c'])
H=nx.Graph()
H.add_cycle(['a1','b1','c1'])
GM = iso.GraphMatcher(H,G)
if GM.subgraph_is_isomorphic()==True:
sub= GM.subgraph_isomorphisms_iter()
for s in sub:
print s
G=nx.Graph()
G.add_path(['a','b','c'])
G1=nx.Graph()
G1.add_path(['a1','b1','c1'])
G1.add_cycle(['d1','b1','e1'])
GM = iso.GraphMatcher(G1,G)
if GM.subgraph_is_isomorphic()==True:
sub= GM.subgraph_isomorphisms_iter()
for s in sub:
print s
the output is
{'a': 2, 'c': 0, 'b': 1, 'd': 3}
{'a': 1, 'c': 3, 'b': 2, 'd': 0}
which is good, but I am not quite sure about second parameter in iso.generic_edge_match().
It seems to be unused since output unchanged even though I modified "2" to others, "blue",eg.
Does I follow the right way of using nx's weighted subgraph matching functionality?
I notice in the first row {'a1': 'a', 'c1': 'c', 'b1': 'b'}
b1 and b “do not have the same number of edges”,
but still can be matched with subISO of networkx.
I probably misunderstood subISO and subMONO,please correct me.