yazdmich

Untitled

Nov 10th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. class node:
  2. def __init__(self, s):
  3. self.serial = s
  4. self.links = []
  5. self.group = 0
  6. self.family = []
  7.  
  8. def join(self, group):
  9. self.group = group
  10.  
  11. def link(self, n):
  12. self.links.append(n)
  13.  
  14. def find_family(self, group, nodes):
  15. for n in nodes:
  16. if n.group == self.group:
  17. self.family.append(n.serial)
  18.  
  19. def find_links(self, nodes):
  20. for n in nodes:
  21. if n.serial not in self.family:
  22. self.link(n)
  23.  
  24.  
  25.  
  26. t = 12
  27. g = 4
  28. gt = int(t/g)
  29. nodes = [node(n) for n in range(t)]
  30. group = 0
  31. for n in range(0,t,int(gt)):
  32. for c in range(gt):
  33. nodes[n+c].join(group)
  34. group += 1
  35.  
  36. for n in nodes:
  37. n.find_family(n.group, nodes)
  38.  
  39. for n in nodes:
  40. print(n.serial, n.group, n.family)
  41.  
  42. for n in nodes:
  43. n.find_links(nodes)
  44.  
  45. links = set()
  46. for n in nodes:
  47. print(str(n.serial)+':')
  48. for m in n.links:
  49. print('\t'+str(m.serial))
  50. links.add((n.serial, m.serial))
  51.  
  52. print(sorted(list(links)))
  53. print(len(links))
Advertisement
Add Comment
Please, Sign In to add comment