Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class node:
- def __init__(self, s):
- self.serial = s
- self.links = []
- self.group = 0
- self.family = []
- def join(self, group):
- self.group = group
- def link(self, n):
- self.links.append(n)
- def find_family(self, group, nodes):
- for n in nodes:
- if n.group == self.group:
- self.family.append(n.serial)
- def find_links(self, nodes):
- for n in nodes:
- if n.serial not in self.family:
- self.link(n)
- t = 12
- g = 4
- gt = int(t/g)
- nodes = [node(n) for n in range(t)]
- group = 0
- for n in range(0,t,int(gt)):
- for c in range(gt):
- nodes[n+c].join(group)
- group += 1
- for n in nodes:
- n.find_family(n.group, nodes)
- for n in nodes:
- print(n.serial, n.group, n.family)
- for n in nodes:
- n.find_links(nodes)
- links = set()
- for n in nodes:
- print(str(n.serial)+':')
- for m in n.links:
- print('\t'+str(m.serial))
- links.add((n.serial, m.serial))
- print(sorted(list(links)))
- print(len(links))
Advertisement
Add Comment
Please, Sign In to add comment