Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create 4x4 grid graph
- G = nx.grid_2d_graph(4,4)
- G.nodes
- # Here you can see that nodes are just points with coordinates
- NodeView(((0, 1), (1, 2), (3, 2), (0, 0), (3, 3), (3, 0), (3, 1), (1, 1), (2, 1), (0, 2), (2, 0), (1, 3), (2, 3), (2, 2), (1, 0), (0, 3)))
- # Set all weights to 1
- for edge in G.edges:
- G.edges[edge]['weight'] = 1
- 0,0 1,0
- 0,1 1,1
- G.add_edges_from([
- ((x, y), (x+1, y+1))
- for x in range(3)
- for y in range(3)
- ] + [
- ((x+1, y), (x, y+1))
- for x in range(3)
- for y in range(3)
- ], weight=1.4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement