redundant_multicast_algorithms.py 文件源码

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

项目:ride 作者: KyleBenson 项目源码 文件源码
def __validate_list(self):
        non_source_sets = self._list[1:-1]
        # every non-source anchor has an incoming neighbor
        # both before and after it in the skeleton list.
        for anchor in (self._get_anchor(t) for t in non_source_sets):
            found_after = False
            found_before = False
            my_idx = self._get_index(anchor)
            for pred in self._get_external_predecessors(anchor):
                pred_idx = self._get_index(pred)
                if pred_idx < my_idx:
                    found_before = True
                # HACK: root is in 2 places!
                if pred == self.root:
                    pred_idx = len(self._list) - 1
                if pred_idx > my_idx:
                    found_after = True

            assert(found_after and found_before)

        # every non-source set is pair-wise disjoint with every other set
        for s1, s2 in itertools.combinations(non_source_sets, 2):
            assert(len(set(s1.nodes()).intersection(s2.nodes())) == 0)

        # directed path from anchor to every other node in its set
        assert(all(nx.is_directed_acyclic_graph(t) for t in non_source_sets))

        # first and last sets are always just the root
        assert(self.root in self._list[0] and self.root in self._list[-1] and\
               self._list[0].number_of_nodes() == 1 and self._list[-1].number_of_nodes() == 1)

        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号