From 3d5e53b8cfea3bfea5f73d56bdcb152bd74ddb99 Mon Sep 17 00:00:00 2001 From: lamelizard Date: Sun, 29 Nov 2020 12:07:45 +0100 Subject: [PATCH] fixed Graph vs. DiGraph bug --- graphwfc/helpers.py | 15 ++++++++++----- setup.py | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/graphwfc/helpers.py b/graphwfc/helpers.py index 9ad83e1..b4b96cb 100644 --- a/graphwfc/helpers.py +++ b/graphwfc/helpers.py @@ -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. @@ -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()} @@ -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, diff --git a/setup.py b/setup.py index 12e76e8..ebb97ed 100644 --- a/setup.py +++ b/setup.py @@ -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", -) \ No newline at end of file +)