def make_graph(): if PROBE_DIM == 0: return complete_graph(N_SITES) elif PROBE_DIM == 1: x = [site.x for site in PROBE_SITES] return path_graph(x) elif PROBE_DIM == 2: xy = [(site.x,site.y) for site in PROBE_SITES] return triangle_graph(xy)
def make_graph(): if PROBE_DIM == 0: return complete_graph(N_SITES) elif PROBE_DIM == 1: x = [site.x for site in PROBE_SITES] return path_graph(x) elif PROBE_DIM == 2: xy = [(site.x, site.y) for site in PROBE_SITES] return triangle_graph(xy)
def triangle_graph(Locs): """ Returns a graph giving the Delaunay triangulation of a set of two-dimensional points Parameters ------- Locs : ndarray, or anything that gets cast into ndarray upon np.array(Locs) Locs.shape = (n,2), where n is the number of points Returns ------ out : networkx Graph """ Locs = np.array(Locs) if len(Locs)==1: return complete_graph(1) else: Triangulation = sd.Triangulation(Locs[:,0],Locs[:,1]) return Triangulation.node_graph()
def triangle_graph(Locs): """ Returns a graph giving the Delaunay triangulation of a set of two-dimensional points Parameters ------- Locs : ndarray, or anything that gets cast into ndarray upon np.array(Locs) Locs.shape = (n,2), where n is the number of points Returns ------ out : networkx Graph """ Locs = np.array(Locs) if len(Locs) == 1: return complete_graph(1) else: Triangulation = sd.Triangulation(Locs[:, 0], Locs[:, 1]) return Triangulation.node_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