-
Notifications
You must be signed in to change notification settings - Fork 0
/
badtree.py
61 lines (47 loc) · 1.65 KB
/
badtree.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
52
53
54
55
56
57
58
59
60
61
#!/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 pygraph
from pygraph.classes.digraph import digraph
from minmax_degree import minimal_spanning_tree # own minimum spanning tree implementation
import algorithms
import overlay
class BadTree(overlay.Overlay):
"""
Build a bad tree.
We use this to show that picking the "right" topology matters.
The idea is to invert the weights and run an MST. The spanning
tree will then be composed of many expensive links
(i.e. cross-NUMA links).
"""
def __init__(self, mod):
"""
Initialize the clustering algorithm
"""
super(BadTree, self).__init__(mod)
def get_name(self):
return "badtree"
def _build_tree(self, g):
"""
We build a bad tree by inverting all edge weights and running
an MST algorithm on the resulting graph.
"""
# Build graph with inverted edges
g_inv = algorithms.invert_weights(g)
# Run binary tree algorithm
mst_inv = minimal_spanning_tree(g_inv, self.get_root_node())
# Build a new graph
badtree = digraph()
# Add nodes
for n in g.nodes():
badtree.add_node(n)
# Add edges, copy weights from non-inverted graph
for (e,s) in mst_inv.items():
if s != None:
badtree.add_edge((s, e), g.edge_weight((s, e)))
return badtree