def add_inter_building_links(self):
"""Adds links between buildings randomly for additional
redundancy and topology diversity."""
try:
endpoints = random.sample(self.major_building_routers, self.inter_building_links * 2)
endpoints = zip(endpoints[:len(endpoints)/2], endpoints[len(endpoints)/2:])
except ValueError as e:
raise ValueError("NOTE: requested more inter_building_links "
"than can be placed without repeating (major) buildings!")
# XXX: this doesn't seem to work for 3 buildings and 2 inter-building links: fuhgedaboudit
if self.inter_building_links > 400:
print "Requested a lot of inter-building links. This may take a while to generate all combinations without repeat..."
endpoints = list(itertools.combinations_with_replacement(self.major_building_routers, 2))
random.shuffle(endpoints)
endpoints = endpoints[:self.inter_building_links]
for src, dst in endpoints:
self.add_link(src, dst)
评论列表
文章目录