Commit bb9781a0 authored by Antoine Kaufmann's avatar Antoine Kaufmann Committed by Hejing Li
Browse files

experiments: add support for e2e partiton by weight

parent 65bdde67
...@@ -58,7 +58,7 @@ class IDMap(object): ...@@ -58,7 +58,7 @@ class IDMap(object):
return self.dict.items() return self.dict.items()
# Split the topology into N networks, return E2ENetwork instances # Split the topology into N networks, return E2ENetwork instances
def partition(topology, N): def partition(topology, N, by_weight=False):
adjlists = collections.defaultdict(tuple) adjlists = collections.defaultdict(tuple)
edges = [] edges = []
idmap = IDMap() idmap = IDMap()
...@@ -78,12 +78,21 @@ def partition(topology, N): ...@@ -78,12 +78,21 @@ def partition(topology, N):
max_node = max(adjlists.keys()) max_node = max(adjlists.keys())
graph = [] graph = []
weights = []
for i in range(0, max_node + 1): for i in range(0, max_node + 1):
c = idmap.from_id(i)
if 'weight' in c.__dict__:
weights.append(c.weight)
else:
weights.append(1)
graph.append(adjlists[i]) graph.append(adjlists[i])
if N == 1: if N == 1:
# metis does not like N=1 :-) # metis does not like N=1 :-)
parts = [0] * (max_node + 1) parts = [0] * (max_node + 1)
else:
if by_weight:
(edgecuts, parts) = metis.part_graph(graph, N, nodew=weights)
else: else:
(edgecuts, parts) = metis.part_graph(graph, N) (edgecuts, parts) = metis.part_graph(graph, N)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment