Skip to content

Commit 3d5e53b

Browse files
committed
fixed Graph vs. DiGraph bug
1 parent 27fca2e commit 3d5e53b

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

graphwfc/helpers.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from 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,

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
setup(
44
name='GraphWFC',
5-
version='0.9.3',
5+
version='0.9.4',
66
author="lamelizard",
77
author_email="florian.drux@rwth-aachen.de",
88
description='Colors a networkx (Di)Graph based on patterns extracted from an colored example (Di)Graph',
99
packages=['graphwfc',],
1010
install_requires=[
11-
'networkx',
11+
'networkx<=2.4',
1212
],
1313
python_requires=">=3.0",
1414
url='https://github.com/lamelizard/GraphWaveFunctionCollapse',
1515
license='MIT',
1616
long_description="A python 3.x package to color a graph based on patterns extracted from an colored example graph. More infos on https://github.com/lamelizard/GraphWaveFunctionCollapse",
17-
)
17+
)

0 commit comments

Comments
 (0)