def grid_fourNN(M,N,strength=1.0):
"""
return an MxN grid graph with 4-nearest-neighbour connectivity
Args:
M,N: desired grid dimensions
strength: desired edge strength
"""
graph = nx.grid_2d_graph(M, N)
graph.graph["grid_dimensions"] = (M,N)
for e in graph.edges_iter():
graph.edge[e[0]][e[1]] = {"strength":strength}
graph.edge[e[1]][e[0]] = {"strength":strength}
return graph
评论列表
文章目录