-
Notifications
You must be signed in to change notification settings - Fork 0
/
binarytree.py
51 lines (38 loc) · 1.11 KB
/
binarytree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
#
# Copyright (c) 2013-2016, ETH Zurich.
# All rights reserved.
#
# This file is distributed under the terms in the attached LICENSE file.
# If you do not find this file, copies can be found by writing to:
# ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
# Import own code
import algorithms
import overlay
class BinaryTree(overlay.Overlay):
"""
Build a cluster topology for a model
"""
def __init__(self, mod):
"""
Initialize the clustering algorithm
"""
super(BinaryTree, self).__init__(mod)
def get_name(self):
return "binarytree"
def _get_broadcast_tree(self):
"""
Return the broadcast tree as a graph
"""
return self.get_bintree(self.mod.get_graph())
def _get_multicast_tree(self, graph):
"""
Run on given multicast tree
"""
return self.get_bintree(graph)
def get_bintree(self, graph):
"""
Generate a binary tree for the given graph.
"""
bintree = algorithms.binary_tree(graph)
return bintree