本文整理汇总了Python中igraph.Graph.is_weighted方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.is_weighted方法的具体用法?Python Graph.is_weighted怎么用?Python Graph.is_weighted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.is_weighted方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_graph
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import is_weighted [as 别名]
def gen_graph():
masters = sum(ms, [])
slaves = sum(ss, [])
frees = sum(fs, [])
ct = machine_count
g = Graph().as_directed()
g.add_vertices(2 * ct + 2)
g.es['weight'] = 1
assert g.is_weighted()
lin = map(len, fs)
# lin = map(operator.add, map(len, ss), map(len, fs))
rout = map(len, ms)
s = 2 * ct
t = s + 1
for i, m in enumerate(lin):
g[s, i] = m
for i, m in enumerate(rout):
g[i + ct, t] = m
cap = defaultdict(dict)
for i, m in enumerate(lin):
for j, n in enumerate(rout):
if i == j:
continue
cap[i][j] = m
assert len(ss) == ct
# for i in range(ct):
# for slave in ss[i]:
# cap[i][slave.master.machine_tag] -= 1
# assert cap[i][slave.master.machine_tag] >= 0
print cap
for i in range(ct):
for j in range(ct):
if i == j:
continue
masters_in_j = set(slave.master.tag for slave in ss[i] if slave.master.machine_tag == j) # to fight existing distribution error
limit = len(ms[j]) - len(masters_in_j)
cap[i][j] = min(limit, map(len, fs)[i])
for i, m in enumerate(lin):
if m == 0:
continue
for j, n in enumerate(rout):
if i == j:
continue
g[i, ct + j] = cap[i][j]
print g
start = datetime.utcnow()
mf = g.maxflow(s, t, g.es['weight'])
end = datetime.utcnow()
print 'result:', end - start
print mf.value, sum(rout)
print mf.flow
print map(float, g.es['weight']), len(g.es['weight'])
示例2: _gen_graph
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import is_weighted [as 别名]
def _gen_graph(self):
g = Graph().as_directed()
g.add_vertices(self.vertex_count)
g.es['weight'] = 1 # enable weight
assert g.is_weighted()
return g