本文整理汇总了Python中igraph.Graph.are_connected方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.are_connected方法的具体用法?Python Graph.are_connected怎么用?Python Graph.are_connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.are_connected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSimMSTs
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import are_connected [as 别名]
def getSimMSTs(self, inverse=True, plotGraph=True, root="UNK"):
rootId1 = self.emb1.d[root]
rootId2 = self.emb2.d[root]
if inverse == True:
d = -1
else:
d = 1
g1 = minimum_spanning_tree(csr_matrix(d*self.s1))
g2 = minimum_spanning_tree(csr_matrix(d*self.s2))
a1 = g1.toarray()
a2 = g2.toarray()
if plotGraph==True:
t1 = Graph()
t2 = Graph()
t3 = Graph()
t1.add_vertices(self.emb1.vocab_size)
t2.add_vertices(self.emb2.vocab_size)
t3.add_vertices(self.emb1.vocab_size)
t1.vs["color"] = "white"
t2.vs["color"] = "white"
t3.vs["color"] = "white"
t1.vs["label"] = [w for w,i in sorted(self.emb1.d.items(), key=itemgetter(1))]
t2.vs["label"] = [w for w,i in sorted(self.emb2.d.items(), key=itemgetter(1))]
t3.vs["label"] = t1.vs["label"]
for i in xrange(a1.shape[0]):
for j in xrange(a1.shape[1]):
if a1[i,j] != 0:
t1.add_edge(i,j, weight=a1[i,j], color="blue")
t3.add_edge(i,j, weight=a1[i,j], color="blue")
for i in xrange(a2.shape[0]):
for j in xrange(a2.shape[1]):
if a2[i,j] != 0:
t2.add_edge(i,j, weight=a2[i,j], color="red")
if t3.are_connected(i,j): #edge in both MSTs
t3.es[i,j]["color"] = "black"
else:
t3.add_edge(i,j, weight=a1[i,j], color="red")
layout1 = t1.layout_reingold_tilford(mode="in", root=rootId1)
layout2 = t2.layout_reingold_tilford(mode="in", root=rootId2)
layout3 = t3.layout_reingold_tilford(mode="in", root=rootId1)
graphs = [Graph.GRG(10, 0.4) for _ in xrange(5)]
figure = Plot(bbox=(0,0,2000,1000))
figure.add(t1, layout=layout1, margin=100, bbox=(0,0,1000,1000))
figure.add(t2, layout=layout2, margin=100, bbox=(1000,0,2000,1000))
plotname1 = "plots/"+NAME+".mst_trees.png"
figure.save(plotname1)
plotname3 = "plots/"+NAME+".merged_mst.png"
plot(t3, plotname3 , layout=layout3, bbox=(1000,1000), margin=100)
print("\tSaved MST plots in '%s', '%s'" % (plotname1, plotname3))
return t1,t2,t3
示例2: len
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import are_connected [as 别名]
g.add_edge(frm,to, updated_ts = tweet_time )
g.vs.find(to)['updated_ts'] = tweet_time
if frm in g.vs['name'] and to not in g.vs['name']:
g.add_vertex(to,updated_ts=tweet_time)
g.add_edge(frm,to, updated_ts = tweet_time )
g.vs.find(frm)['updated_ts'] = tweet_time
if frm in g.vs['name'] and to in g.vs['name']:
g.vs.find(frm)['updated_ts'] = tweet_time
g.vs.find(to)['updated_ts'] = tweet_time
"""
if two exiting nodes are there, no need to create new edge. Just
update updated_ts to reflect the latest time
"""
if not g.are_connected((g.vs.find(frm)).index,(g.vs.find(to)).index):
g.add_edge(frm,to, updated_ts = tweet_time )
if len(g.degree()) > 1:
average = sum(g.degree())/len(g.degree())
else:
average = 0.00
ft2.write("{0:.2f}".format(average) + '\n')
line_generator.close()
ft2.close()