Skip to content

Commit

Permalink
fixed Graph vs. DiGraph bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lamelizard committed Nov 29, 2020
1 parent 27fca2e commit 3d5e53b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 10 additions & 5 deletions graphwfc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from collections import defaultdict


def get_isos(GB: DiGraph, GLs, edge_attr='type'):
"""returns the isomorphisms from every GL in GLs to a node induced subgraph of G as a ordered list of nodes
def get_isos(GB, GLs, edge_attr='type'):
"""returns the isomorphisms from every GL in GLs to a node induced subgraph of GB as a ordered list of nodes
This function is used to get the needed isos. Usually called with GI or GO as G.
This function is used to get the needed isos. Usually called with GI or GO as GB.
While this is called by the GraphWFCState constructor it might be useful
to call it yourself and cache the results if some graphs are used multiple times.
Expand All @@ -25,7 +25,12 @@ def get_isos(GB: DiGraph, GLs, edge_attr='type'):
iso_count = 0
order = sorted(GL.nodes())
edgetest = isomorphism.categorical_edge_match(edge_attr, -1)
matcher = isomorphism.DiGraphMatcher(GB, GL, edge_match=edgetest)
if nx.is_directed(GB) and nx.is_directed(GL):
matcher = isomorphism.DiGraphMatcher(GB, GL, edge_match=edgetest)
elif (not nx.is_directed(GB)) and (not nx.is_directed(GL)):
matcher = isomorphism.GraphMatcher(GB, GL, edge_match=edgetest)
else:
raise TypeError('You may not use both directed and undirected graphs.')
iso_list = list()
for iso_GBtoGL in matcher.subgraph_isomorphisms_iter():
iso_GLtoGB = {GL_node: GB_node for GB_node, GL_node in iso_GBtoGL.items()}
Expand All @@ -40,7 +45,7 @@ def get_isos(GB: DiGraph, GLs, edge_attr='type'):
return GB_isos_per_GL


def get_patterns(GI: DiGraph, GLs=None, GI_isos_per_GL=None, node_attr='color', edge_attr='type'):
def get_patterns(GI, GLs=None, GI_isos_per_GL=None, node_attr='color', edge_attr='type'):
"""extracts the patterns from GI for each GL and counts them
This is called by the GraphWFCState constructor. If neither GI nor GLs differ for two GraphWFCStates,
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

setup(
name='GraphWFC',
version='0.9.3',
version='0.9.4',
author="lamelizard",
author_email="florian.drux@rwth-aachen.de",
description='Colors a networkx (Di)Graph based on patterns extracted from an colored example (Di)Graph',
packages=['graphwfc',],
install_requires=[
'networkx',
'networkx<=2.4',
],
python_requires=">=3.0",
url='https://github.com/lamelizard/GraphWaveFunctionCollapse',
license='MIT',
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",
)
)

0 comments on commit 3d5e53b

Please sign in to comment.