Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random as RD
- import networkx as NX
- import matplotlib
- import math as MT
- N=101 # number of vertices (sensors)
- minScope = 20
- maxScope = 120
- rangeX = (5, 295)
- rangeY = (5,295)
- scopeRad = (minScope, maxScope)
- D = NX.DiGraph()
- arrScope = [[]]
- for i in range(1,N):
- x= float(RD.randrange(*rangeX))
- y= float(RD.randrange(*rangeY))
- positions =(x,y)
- rndRad = RD.randrange(*scopeRad)
- D.add_node(i, pos=(x,y))
- arrScope.append([i,rndRad])
- pos = NX.get_node_attributes(D, 'pos')
- for i in range(1,N):
- for j in range(1,N):
- x1, y1 = pos[i]
- x2, y2 = pos[j]
- if i != j:
- if (MT.sqrt( MT.pow((x2-x1),2) + MT.pow((y2-y1),2) ))<=arrScope[i][1]:
- D.add_edge(i,j)
- print(NX.number_of_edges(D))
- NX.draw(D, pos, with_labels=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement