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 edge_iso_match(attr, attr_default, op): """ Returns an edge_match function that can be used in find_sub_iso() Args: - attr: the name (or list of names) of attributes to consider. - attr_default: default value (or list of values) for attributes - op: a callable boolean function. Note: This function in its current form is just a wrapper around networkx.isomorphism.generic_edge_match() """ em = isomorphism.generic_edge_match(attr, attr_default, op) return em
"e3": "b2", "e4": "b3", "e5": "b2", "e6": "b3" } TARGET_MAP = { "e1": "b2", "e2": "b4", "e3": "b3", "e4": "b2", "e5": "b4", "e6": "b4" } WEIGHT_MAP = {"e1": 6, "e2": 1, "e3": 10, "e4": 10, "e5": 12, "e6": 8} DEEP_CYCLES = [{"e3", "e4"}, {"e4", "e5", "e6"}] EM = generic_edge_match(["weight", "label"], [0, "b1"], [close, eq]) _ATTR_LABEL = "label" _ATTR = "weight" @pytest.fixture(scope="module") def dg() -> nx.MultiDiGraph: """Init a case from page 237 in [camerini1980ranking]_ .""" res = nx.MultiDiGraph() res.add_edge("b1", "b2", label="e1", weight=6) res.add_edge("b1", "b4", label="e2", weight=1) res.add_edge("b2", "b3", label="e3", weight=10) res.add_edge("b3", "b2", label="e4", weight=10) res.add_edge("b2", "b4", label="e5", weight=12) res.add_edge("b4", "b3", label="e6", weight=8) return res