Commit e163e5a3 authored by Morten Knutsen's avatar Morten Knutsen Committed by Morten Knutsen
Browse files

Port edges-retrieval to 0.99 API

Use .edges(data=True) where applicable.
parent 434d9dfc
......@@ -331,7 +331,7 @@ class MetricShell(Cmd):
if self.simulation.linkloads:
cmap = {}
capa = {}
for (u,v,d) in self.simulation.graph.edges():
for (u,v,d) in self.simulation.graph.edges(data=True):
cmap[(u,v)] = self.simulation.get_link_utilization(u,v)
capa[(u,v)] = self.model.get_link_capacity(u,v)
else:
......@@ -348,7 +348,7 @@ class MetricShell(Cmd):
G = self.simulation.graph
graphdata['labels'] = utils.short_names(G.nodes())
graphdata['edgelabels'] = utils.edge_labels(G.edges(),
graphdata['edgelabels'] = utils.edge_labels(G.edges(data=True),
graphdata['edgegroups'])
graphdata['pos'] = self.model.get_positions(G.nodes())
......@@ -387,7 +387,7 @@ class MetricShell(Cmd):
if self.model.linkloads:
cmap = {}
capa = {}
for (u,v,d) in self.model.graph.edges():
for (u,v,d) in self.model.graph.edges(data=True):
cmap[(u,v)] = self.model.get_link_utilization(u,v)
capa[(u,v)] = self.model.get_link_capacity(u,v)
else:
......@@ -399,7 +399,7 @@ class MetricShell(Cmd):
graphdata['nodegroups'] = self.model.get_node_groups()
graphdata['edgegroups'] = self.model.get_edge_groups()
graphdata['labels'] = utils.short_names(G.nodes())
graphdata['edgelabels'] = utils.edge_labels(G.edges(),
graphdata['edgelabels'] = utils.edge_labels(G.edges(data=True),
graphdata['edgegroups'])
graphdata['pos'] = self.model.get_positions(G.nodes())
graphdata['title'] = "Current topology"
......@@ -426,7 +426,7 @@ class MetricShell(Cmd):
graphdata['areagroups'] = areas
graphdata['edgegroups'] = self.model.get_edge_groups()
graphdata['labels'] = utils.short_names(G.nodes())
graphdata['edgelabels'] = utils.edge_labels(G.edges(),
graphdata['edgelabels'] = utils.edge_labels(G.edges(data=True),
graphdata['edgegroups'])
graphdata['pos'] = self.model.get_positions(G.nodes())
graphdata['title'] = "Current topology with IS-IS areas"
......@@ -670,7 +670,7 @@ class MetricShell(Cmd):
graphdata['acgroups'] = acgroups
graphdata['edgegroups'] = self.simulation.get_edge_groups()
graphdata['labels'] = utils.short_names(G.nodes())
graphdata['edgelabels'] = utils.edge_labels(G.edges(),
graphdata['edgelabels'] = utils.edge_labels(G.edges(data=True),
graphdata['edgegroups'])
graphdata['pos'] = self.model.get_positions(G.nodes())
graphdata['title'] = "Simulated topology with anycast groups"
......@@ -782,7 +782,7 @@ class MetricShell(Cmd):
shown = {}
header = False
for (u,v,w) in sorted(H.edges()):
for (u,v,w) in sorted(H.edges(data=True)):
if (u,v) in shown: continue
w_old = G.get_edge(u,v)
if w_old != w:
......@@ -802,7 +802,7 @@ class MetricShell(Cmd):
applied = {}
if apply.lower() == 'y':
for (u,v,w) in H.edges():
for (u,v,w) in H.edges(data=True):
if (u,v) in applied: continue
w_old = G.get_edge(u,v)
if w_old != w:
......@@ -932,7 +932,7 @@ class MetricShell(Cmd):
graphdata['nodegroups'] = self.simulation.get_node_groups(path=path)
graphdata['edgegroups'] = self.simulation.get_edge_groups(path=paths)
graphdata['labels'] = utils.short_names(G.nodes())
graphdata['edgelabels'] = utils.edge_labels(G.edges(),
graphdata['edgelabels'] = utils.edge_labels(G.edges(data=True),
graphdata['edgegroups'])
graphdata['pos'] = self.model.get_positions(G.nodes())
graphdata['title'] = "Simulated path from %s to %s (cost: %d, %s hops)" \
......@@ -1020,7 +1020,7 @@ class MetricShell(Cmd):
geg = self.simulation.get_diff_edge_groups(paths,spaths)
lb = utils.short_names(H.nodes())
elb = utils.edge_labels(H.edges(), geg)
elb = utils.edge_labels(H.edges(data=True), geg)
pos = self.model.get_positions(H.nodes())
graphdata['title'] = "Simulated path from %s to %s (cost: %d, %s hops)" \
% (a, b, slength, shops)
......@@ -1122,7 +1122,7 @@ class MetricShell(Cmd):
graphdata['nodegroups'] = self.model.get_node_groups(path=path)
graphdata['edgegroups'] = self.model.get_edge_groups(path=paths)
graphdata['labels'] = utils.short_names(G.nodes())
graphdata['edgelabels'] = utils.edge_labels(G.edges(),
graphdata['edgelabels'] = utils.edge_labels(G.edges(data=True),
graphdata['edgegroups'])
graphdata['pos'] = self.model.get_positions(G.nodes())
graphdata['title'] = "Path(s) from %s to %s (cost: %d, %s hops)" \
......
......@@ -414,7 +414,7 @@ class Model:
def get_link_utilizations(self):
utils = {}
for (u,v,d) in self.G.edges():
for (u,v,d) in self.G.edges(data=True):
utils[(u,v)] = self.get_link_utilization(u,v)
return utils
......@@ -444,7 +444,7 @@ class Model:
ebc = self.edge_betweenness
top = self.get_edge_betweenness(top=n)
for (u, v, d) in self.G.edges():
for (u, v, d) in self.G.edges(data=True):
if edges != None and (u, v) not in edges:
continue
if (ebc[(u,v)] > threshold and ebc[(v,u)] > threshold) \
......@@ -582,7 +582,7 @@ class Model:
def _make_weighted_copy(self):
G = self.graph.copy()
for (u,v,d) in G.edges():
for (u,v,d) in G.edges(data=True):
G.delete_edge(u,v)
G.add_edge(u,v,d['value'])
return G
......@@ -690,7 +690,7 @@ class Simulation:
def get_link_utilizations(self):
utils = {}
for (u,v,d) in self.graph.edges():
for (u,v,d) in self.graph.edges(data=True):
utils[(u,v)] = self.get_link_utilization(u,v)
return utils
......@@ -1025,10 +1025,10 @@ class Simulation:
top = self.get_edge_betweenness(top=n)
redges = list(set([(u,v) for (u,v,w) in self.model.G.edges()]) \
- set([(u,v) for (u,v,w) in self.graph.edges()]))
redges = list(set([(u,v) for (u,v,w) in self.model.G.edges(data=True)]) \
- set([(u,v) for (u,v,w) in self.graph.edges(data=True)]))
for (u, v, d) in self.graph.edges():
for (u, v, d) in self.graph.edges(data=True):
debug = False
#if u == 'oslo-gw' or v == 'oslo-gw': debug = True
if debug: print "Looking at (%s, %s, %s)" % (u, v, d)
......@@ -1280,7 +1280,7 @@ class Simulation:
ebc = self.edge_betweenness
top = self.get_edge_betweenness(top=n)
for (u, v, d) in self.graph.edges():
for (u, v, d) in self.graph.edges(data=True):
if (ebc[(u,v)] > threshold and ebc[(v,u)] > threshold) \
or (u,v) in top:
if (path != None) and (not multi) and ((u,v) in mpath_edges):
......@@ -1802,7 +1802,7 @@ class Simulation:
if debug: print "nochange was False, so going on"
for (u,v,w) in K.edges():
for (u,v,w) in K.edges(data=True):
if (u,v) in results: continue
old_w = G.get_edge(u,v)
if old_w != w:
......@@ -1828,7 +1828,7 @@ class Simulation:
G = self.graph
H = self.graph.copy()
edges = sorted(H.edges(), cmp=lambda x,y: cmp(y[2], x[2]) \
edges = sorted(H.edges(data=True), cmp=lambda x,y: cmp(y[2], x[2]) \
or cmp(ebc[(x[0],x[1])],
ebc[(y[0],y[1])]))
......
......@@ -31,7 +31,7 @@ def parse_pajek(lines):
import shlex
if is_string_like(lines): lines=iter(lines.split('\n'))
lines = iter([line.rstrip('\n') for line in lines])
G=networkx.XDiGraph(selfloops=True) # are multiedges allowed in Pajek?
G=networkx.DiGraph() # are multiedges allowed in Pajek?
G.node_attr={} # dictionary to hold node attributes
directed=True # assume this is a directed network for now
while lines:
......
......@@ -330,7 +330,7 @@ class PlotUI:
from math import sqrt
lpos = []
for (u,v,w) in G.edges():
for (u,v,w) in G.edges(data=True):
(x1, y1) = pos[u]
(x2, y2) = pos[v]
......
......@@ -104,7 +104,7 @@ def read_linkloads(G, host, url):
loads_by_descr[descr] = (avg_out, avg_in)
for (u,v,edgedata) in G.edges():
for (u,v,edgedata) in G.edges(data=True):
if not 'l' in edgedata: continue
label = edgedata['l']
if label in loads_by_descr:
......
Supports Markdown
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