def check_patterns(G1, G2, saveisolist=False, readisolist=False, plot=False): # Check isomorphism GM = GraphMatcher(G1=G1, G2=G2, node_match=None, edge_match=None) isomorph = GM.subgraph_is_isomorphic() if saveisolist: # Check if the pickles folder exists if not os.path.isdir("./pickles/"): os.makedirs("./pickles/") # List all isomorphisms between the two graphs isomorph_list = list(GM.subgraph_isomorphisms_iter()) # Save isomorphism list pickling_on = open('pickles/arch2_patt8.pickle', "wb") pickle.dump(isomorph_list, pickling_on) pickling_on.close() if readisolist: # Read pickle file pickle_off = open('pickles/arch2_patt8.pickle', "rb") isomorph_list = pickle.load(pickle_off) pickle_off.close() if plot: # Plot a sample isomorph options = { 'line_color': 'grey', 'font_size': 10, 'node_size': 10, 'with_labels': True } G3 = G1.subgraph(isomorph_list[0]) plt.figure(1) nx.draw(G3, **options) plt.figure(2) nx.draw(G2, **options) plt.show() return isomorph
def subgraph_match(self): complete_subgraph = nx.complete_graph(self.args.sub_graph_size) gm = GraphMatcher(self.complete_graph, complete_subgraph) is_isomorphic = gm.subgraph_is_isomorphic() print("Is isomorphic?: {}".format(is_isomorphic))