当前位置: 首页>>代码示例>>Python>>正文


Python Graph.es["weight"]方法代码示例

本文整理汇总了Python中igraph.Graph.es["weight"]方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.es["weight"]方法的具体用法?Python Graph.es["weight"]怎么用?Python Graph.es["weight"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在igraph.Graph的用法示例。


在下文中一共展示了Graph.es["weight"]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: range

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es["weight"] [as 别名]

vertices = range(int(np.max(graph[:,1:3]))+1)
#print vertices
edges = graph[:,1:3].astype(int).tolist()
weights = graph[:,3].tolist()
#print edges
#print weights
g = Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)
out = g.get_shortest_paths(18, to=19, weights=weights, output="vpath")
print out
out = g.get_shortest_paths(18, to=[11,19], weights=weights, output="epath")
print out
print len(g.es)
#print [e for e in g.es]

g.es["weight"] = weights
out = g.get_shortest_paths(18, to=19, weights="weight", output="vpath")
print out
out = g.get_shortest_paths(18, to=[11,19], weights="weight", output="epath")
print out

vertices = range(int(np.max(graph[:,1:3]))+2)
print vertices
print edges
edges.append([20,19])
weights.append(1.0)
g = Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)
g.es["weight"] = weights
out = g.get_shortest_paths(18, to=[11,19,20], weights=weights, output="vpath")
print out
开发者ID:megacell,项目名称:python-traffic-assignment,代码行数:32,代码来源:scripts_igraph.py

示例2: enumerate

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es["weight"] [as 别名]
adjList = {}
for row in rowlist:
    tags = row.getAttribute("Tags")
    taglist = tags.encode('utf-8').strip("><").split("><")
    del tags
    for i, source in enumerate(taglist):
        for target in taglist[i + 1:]:
            e = (source, target)
            if e[0] > e[1]:
                e = (target, source)
             

# cant add an edge if one of the verices are not made
g = Graph()
# print g
g.es["weight"] = 1.0

gen = UniqueIdGenerator()

for e in adjList:
    # print e[0], e[1]
    if e[0] not in gen:
        sourceVertex = {}
        # sourceVertex["uid"] = gen[e[0]]
        sourceVertex = e[0]
        g.add_vertex(sourceVertex)
        # print g
    if e[1] not in gen:
        targetVertex = {}
        # targetVertex["uid"] = gen[e[1]]
        targetVertex = e[1]
开发者ID:abpoms,项目名称:info-overflow,代码行数:33,代码来源:simpleGraphWriter.py

示例3: Graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es["weight"] [as 别名]
from igraph import Graph,plot
g = Graph([(0,1), (0,2), (0,3), (0,4), (5,2), (3,5), (5,0), (4,3), (3,6)],directed = True)
g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
g.es["weight"] = [1,5,3,7,6,2,9,5,7]
g.vs["age"] = [25, 31, 18, 47, 22, 23, 50]
g.vs["gender"] = ["f", "m", "f", "m", "f", "m", "m"]
g.es["is_formal"] = [False, False, True, True, True, False, True, False, False]
layout = g.layout_fruchterman_reingold()
g.vs["label"] = g.vs["name"]
color_dict = {"m": "blue", "f": "pink"}
g.vs["color"] = [color_dict[gender] for gender in g.vs["gender"]]
# plot(g, layout = layout, bbox = (500, 500), margin = 20)
visual_style = {}
visual_style["vertex_size"] = 20
visual_style["vertex_color"] = [color_dict[gender] for gender in g.vs["gender"]]
visual_style["vertex_label"] = g.vs["name"]
visual_style["edge_width"] = [1 + 2 * int(is_formal) for is_formal in g.es["is_formal"]]
visual_style["layout"] = layout
visual_style["bbox"] = (300, 300)
visual_style["margin"] = 20
plot(g, **visual_style)

# print g
开发者ID:drstarry,项目名称:topic-river-flow,代码行数:25,代码来源:layout.py


注:本文中的igraph.Graph.es["weight"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。