Guest User

Untitled

a guest
Apr 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. def dist(I,J):
  2. return math.sqrt( (I[0]-J[0])**2 + (I[1]-J[1])**2 )
  3. G=nx.empty_graph(N) #empty graph
  4. I=[(random.random(),random.random()) for i in range(0,N)] #nodes positions
  5. for i in range(0,N-1):
  6. for j in range(i+1,N):
  7. xm=0.5*(I[i][0] + I[j][0]) #M is the center of i and j
  8. ym=0.5*(I[i][1] + I[j][1])
  9. M=(xm,ym)
  10. d=min(dist(M,I[i]),dist(M,I[j])) #d is the half-distance between i and j
  11. possibilites=[k for k in range(0,N) if xm-d<I[k][0]<xm+d and ym-d<I[k][1]<ym+d] #we are only looking around the point M
  12. inter=[k for k in possibilites if dist(I[k],M)<d]
  13. if len(inter)==0:
  14. G.add_edge(i,j)
Add Comment
Please, Sign In to add comment