Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. # Create 4x4 grid graph
  2. G = nx.grid_2d_graph(4,4)
  3. G.nodes
  4.  
  5. # Here you can see that nodes are just points with coordinates
  6. 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)))
  7.  
  8. # Set all weights to 1
  9. for edge in G.edges:
  10. G.edges[edge]['weight'] = 1
  11.  
  12. 0,0 1,0
  13.  
  14.  
  15. 0,1 1,1
  16.  
  17. G.add_edges_from([
  18. ((x, y), (x+1, y+1))
  19. for x in range(3)
  20. for y in range(3)
  21. ] + [
  22. ((x+1, y), (x, y+1))
  23. for x in range(3)
  24. for y in range(3)
  25. ], weight=1.4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement