def edge_lines_to_graph(edge_lines): probe_graph = dict([(i_site,set([])) for i_site in xrange(N_SITES)]) site_names = [site.name for site in PROBE_SITES] for line in edge_lines: src,targ = line.split() add_edge(probe_graph,site_names.index(src),site_names.index(targ)) return probe_graph
def edge_lines_to_graph(edge_lines): probe_graph = dict([(i_site, set([])) for i_site in xrange(N_SITES)]) site_names = [site.name for site in PROBE_SITES] for line in edge_lines: src, targ = line.split() add_edge(probe_graph, site_names.index(src), site_names.index(targ)) return probe_graph
def path_graph(Locs): """ Returns a line graph for a set of one-dimensional locations. Parameters ------- Locs : ndarray, or anything that gets cast into ndarray upon np.array(Locs) Returns ------ out : graph, i.e. dictionary key -> set(keys) """ Locs = np.array(Locs).flatten() if len(Locs)==1: return complete_graph(1) else: G = {} SortInds = np.argsort(Locs) for src,targ in zip(SortInds[1:],SortInds[:-1]): add_edge(G,src,targ) return G
def path_graph(Locs): """ Returns a line graph for a set of one-dimensional locations. Parameters ------- Locs : ndarray, or anything that gets cast into ndarray upon np.array(Locs) Returns ------ out : graph, i.e. dictionary key -> set(keys) """ Locs = np.array(Locs).flatten() if len(Locs) == 1: return complete_graph(1) else: G = {} SortInds = np.argsort(Locs) for src, targ in zip(SortInds[1:], SortInds[:-1]): add_edge(G, src, targ) return G