Advertisement
Guest User

Untitled

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