Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import random as RD
  2. import networkx as NX
  3. import matplotlib
  4. import math as MT
  5.  
  6. N=101 # number of vertices (sensors)
  7. minScope = 20
  8. maxScope = 120
  9. rangeX = (5, 295)
  10. rangeY = (5,295)
  11. scopeRad = (minScope, maxScope)
  12.  
  13. D = NX.DiGraph()
  14.  
  15. arrScope = [[]]
  16. for i in range(1,N):
  17. x= float(RD.randrange(*rangeX))
  18. y= float(RD.randrange(*rangeY))
  19. positions =(x,y)
  20. rndRad = RD.randrange(*scopeRad)
  21. D.add_node(i, pos=(x,y))
  22. arrScope.append([i,rndRad])
  23. pos = NX.get_node_attributes(D, 'pos')
  24.  
  25. for i in range(1,N):
  26. for j in range(1,N):
  27. x1, y1 = pos[i]
  28. x2, y2 = pos[j]
  29. if i != j:
  30. if (MT.sqrt( MT.pow((x2-x1),2) + MT.pow((y2-y1),2) ))<=arrScope[i][1]:
  31. D.add_edge(i,j)
  32.  
  33. print(NX.number_of_edges(D))
  34. NX.draw(D, pos, with_labels=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement