44from collections import defaultdict
55
66
7- def get_isos (GB : DiGraph , GLs , edge_attr = 'type' ):
8- """returns the isomorphisms from every GL in GLs to a node induced subgraph of G as a ordered list of nodes
7+ def get_isos (GB , GLs , edge_attr = 'type' ):
8+ """returns the isomorphisms from every GL in GLs to a node induced subgraph of GB as a ordered list of nodes
99
10- This function is used to get the needed isos. Usually called with GI or GO as G .
10+ This function is used to get the needed isos. Usually called with GI or GO as GB .
1111 While this is called by the GraphWFCState constructor it might be useful
1212 to call it yourself and cache the results if some graphs are used multiple times.
1313
@@ -25,7 +25,12 @@ def get_isos(GB: DiGraph, GLs, edge_attr='type'):
2525 iso_count = 0
2626 order = sorted (GL .nodes ())
2727 edgetest = isomorphism .categorical_edge_match (edge_attr , - 1 )
28- matcher = isomorphism .DiGraphMatcher (GB , GL , edge_match = edgetest )
28+ if nx .is_directed (GB ) and nx .is_directed (GL ):
29+ matcher = isomorphism .DiGraphMatcher (GB , GL , edge_match = edgetest )
30+ elif (not nx .is_directed (GB )) and (not nx .is_directed (GL )):
31+ matcher = isomorphism .GraphMatcher (GB , GL , edge_match = edgetest )
32+ else :
33+ raise TypeError ('You may not use both directed and undirected graphs.' )
2934 iso_list = list ()
3035 for iso_GBtoGL in matcher .subgraph_isomorphisms_iter ():
3136 iso_GLtoGB = {GL_node : GB_node for GB_node , GL_node in iso_GBtoGL .items ()}
@@ -40,7 +45,7 @@ def get_isos(GB: DiGraph, GLs, edge_attr='type'):
4045 return GB_isos_per_GL
4146
4247
43- def get_patterns (GI : DiGraph , GLs = None , GI_isos_per_GL = None , node_attr = 'color' , edge_attr = 'type' ):
48+ def get_patterns (GI , GLs = None , GI_isos_per_GL = None , node_attr = 'color' , edge_attr = 'type' ):
4449 """extracts the patterns from GI for each GL and counts them
4550
4651 This is called by the GraphWFCState constructor. If neither GI nor GLs differ for two GraphWFCStates,
0 commit comments