def minimum_weighted_edge(one_vertix, other_vertix, graphs_universe): '''Find the minimum weigthed edge and returns the minimum weight to compose a new edge in the final graph.''' logger = logging.getLogger('guiraldelli.master.unification.algorithms.minimum_weighted_edge') logger.setLevel(logging.WARN) inspection_edge = (one_vertix, other_vertix) minimum_weight = None for graph in graphs_universe: if graph.has_edge(inspection_edge): if minimum_weight == None or graph.edge_weight(inspection_edge) < minimum_weight: minimum_weight = graph.edge_weight(inspection_edge) logger.info("Selected edge from the graph %s.", md5.new(str(graph)).hexdigest()) # NOTE: there is no need to receive the edge else: pass else: pass logger.debug('For edge (%s, %s) minimum weight is %s.', one_vertix, other_vertix, minimum_weight) return minimum_weight
def save_graph_text(filename, graph): file = open(filename, 'w') file.write("Nodes: " + str(len(graph.nodes()))) file.write("\n") file.write("Edges: " + str(len(graph.edges())/2)) file.write("\n") edges_saved = list() for edge in sorted(graph.edges()): pair = set() pair.add(edge[0]) pair.add(edge[1]) if pair not in edges_saved: edges_saved.append(pair) edge_to_save = "(%s, %d)" % (edge, graph.edge_weight(edge)) file.write(edge_to_save) file.write("\n") else: pass