campus_topo_gen.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ride 作者: KyleBenson 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号