def build(self): g1 = self.g1 g2 = self.g2 # We will assume integer weights only. g1.add_edge('A', 'B', color='green', weight=0, size=.5) g1.add_edge('A', 'B', color='red', weight=1, size=.35) g1.add_edge('A', 'B', color='red', weight=2, size=.65) g2.add_edge('C', 'D', color='green', weight=1, size=.5) g2.add_edge('C', 'D', color='red', weight=0, size=.45) g2.add_edge('C', 'D', color='red', weight=2, size=.65) if g1.is_multigraph(): self.em = iso.numerical_multiedge_match('weight', 1) self.emc = iso.categorical_multiedge_match('color', '') self.emcm = iso.categorical_multiedge_match(['color', 'weight'], ['', 1]) self.emg1 = iso.generic_multiedge_match('color', 'red', eq) self.emg2 = iso.generic_multiedge_match( ['color', 'weight', 'size'], ['red', 1, .5], [eq, eq, iso.matchhelpers.close]) else: self.em = iso.numerical_edge_match('weight', 1) self.emc = iso.categorical_edge_match('color', '') self.emcm = iso.categorical_edge_match(['color', 'weight'], ['', 1]) self.emg1 = iso.generic_multiedge_match('color', 'red', eq) self.emg2 = iso.generic_edge_match( ['color', 'weight', 'size'], ['red', 1, .5], [eq, eq, iso.matchhelpers.close])
def build(self): g1 = self.g1 g2 = self.g2 # We will assume integer weights only. g1.add_edge('A', 'B', color='green', weight=0, size=.5) g1.add_edge('A', 'B', color='red', weight=1, size=.35) g1.add_edge('A', 'B', color='red', weight=2, size=.65) g2.add_edge('C', 'D', color='green', weight=1, size=.5) g2.add_edge('C', 'D', color='red', weight=0, size=.45) g2.add_edge('C', 'D', color='red', weight=2, size=.65) if g1.is_multigraph(): self.em = iso.numerical_multiedge_match('weight', 1) self.emc = iso.categorical_multiedge_match('color', '') self.emcm = iso.categorical_multiedge_match(['color', 'weight'], ['', 1]) self.emg1 = iso.generic_multiedge_match('color', 'red', eq) self.emg2 = iso.generic_multiedge_match(['color', 'weight', 'size'], ['red', 1, .5], [eq, eq, iso.matchhelpers.close]) else: self.em = iso.numerical_edge_match('weight', 1) self.emc = iso.categorical_edge_match('color', '') self.emcm = iso.categorical_edge_match(['color', 'weight'], ['', 1]) self.emg1 = iso.generic_multiedge_match('color', 'red', eq) self.emg2 = iso.generic_edge_match(['color', 'weight', 'size'], ['red', 1, .5], [eq, eq, iso.matchhelpers.close])
def build(self): g1 = self.g1 g2 = self.g2 # We will assume integer weights only. g1.add_edge("A", "B", color="green", weight=0, size=0.5) g1.add_edge("A", "B", color="red", weight=1, size=0.35) g1.add_edge("A", "B", color="red", weight=2, size=0.65) g2.add_edge("C", "D", color="green", weight=1, size=0.5) g2.add_edge("C", "D", color="red", weight=0, size=0.45) g2.add_edge("C", "D", color="red", weight=2, size=0.65) if g1.is_multigraph(): self.em = iso.numerical_multiedge_match("weight", 1) self.emc = iso.categorical_multiedge_match("color", "") self.emcm = iso.categorical_multiedge_match(["color", "weight"], ["", 1]) self.emg1 = iso.generic_multiedge_match("color", "red", eq) self.emg2 = iso.generic_multiedge_match( ["color", "weight", "size"], ["red", 1, 0.5], [eq, eq, iso.matchhelpers.close], ) else: self.em = iso.numerical_edge_match("weight", 1) self.emc = iso.categorical_edge_match("color", "") self.emcm = iso.categorical_edge_match(["color", "weight"], ["", 1]) self.emg1 = iso.generic_multiedge_match("color", "red", eq) self.emg2 = iso.generic_edge_match( ["color", "weight", "size"], ["red", 1, 0.5], [eq, eq, iso.matchhelpers.close], )
def test_simple(): # 16 simple tests w = 'weight' edges = [(0, 0, 1), (0, 0, 1.5), (0, 1, 2), (1, 0, 3)] for g1 in [ nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph(), ]: g1.add_weighted_edges_from(edges) g2 = g1.subgraph(g1.nodes()) if g1.is_multigraph(): em = iso.numerical_multiedge_match('weight', 1) else: em = iso.numerical_edge_match('weight', 1) assert_true(nx.is_isomorphic(g1, g2, edge_match=em)) for mod1, mod2 in [(False, True), (True, False), (True, True)]: # mod1 tests a regular edge # mod2 tests a selfloop if g2.is_multigraph(): if mod1: data1 = {0: {'weight': 10}} if mod2: data2 = {0: {'weight': 1}, 1: {'weight': 2.5}} else: if mod1: data1 = {'weight': 10} if mod2: data2 = {'weight': 2.5} g2 = g1.subgraph(g1.nodes()).copy() if mod1: if not g1.is_directed(): g2._adj[1][0] = data1 g2._adj[0][1] = data1 else: g2._succ[1][0] = data1 g2._pred[0][1] = data1 if mod2: if not g1.is_directed(): g2._adj[0][0] = data2 else: g2._succ[0][0] = data2 g2._pred[0][0] = data2 assert_false(nx.is_isomorphic(g1, g2, edge_match=em))
def test_simple(): # 16 simple tests w = 'weight' edges = [(0, 0, 1), (0, 0, 1.5), (0, 1, 2), (1, 0, 3)] for g1 in [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph(), ]: g1.add_weighted_edges_from(edges) g2 = g1.subgraph(g1.nodes()) if g1.is_multigraph(): em = iso.numerical_multiedge_match('weight', 1) else: em = iso.numerical_edge_match('weight', 1) assert_true( nx.is_isomorphic(g1, g2, edge_match=em) ) for mod1, mod2 in [(False, True), (True, False), (True, True)]: # mod1 tests a regular edge # mod2 tests a selfloop if g2.is_multigraph(): if mod1: data1 = {0: {'weight': 10}} if mod2: data2 = {0: {'weight': 1}, 1: {'weight': 2.5}} else: if mod1: data1 = {'weight': 10} if mod2: data2 = {'weight': 2.5} g2 = g1.subgraph(g1.nodes()).copy() if mod1: if not g1.is_directed(): g2._adj[1][0] = data1 g2._adj[0][1] = data1 else: g2._succ[1][0] = data1 g2._pred[0][1] = data1 if mod2: if not g1.is_directed(): g2._adj[0][0] = data2 else: g2._succ[0][0] = data2 g2._pred[0][0] = data2 assert_false(nx.is_isomorphic(g1, g2, edge_match=em))