本文整理汇总了Python中Graph.Graph.set_edge_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.set_edge_attribute方法的具体用法?Python Graph.set_edge_attribute怎么用?Python Graph.set_edge_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.set_edge_attribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_graph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import set_edge_attribute [as 别名]
def build_graph(data):
g = Graph()
dict = {}
for v in data["nodes"]:
g.add_vertex(v.id)
g.set_node_attribute({v.id: v})
dict[id] = v
for e in data["edges"]:
source = e["source"]
target = e["target"]
g.add_edge((source,target))
g.set_edge_attribute({(source,target):e})
return g
示例2: edge_product_graph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import set_edge_attribute [as 别名]
def edge_product_graph(self, g1, g2):
result = Graph()
for e1 in g1.edges():
for e2 in g2.edges():
if g1.get_edge_attribute(e1) == None:
continue
if g2.get_edge_attribute(e2) == None:
continue
if g1.get_edge_attribute(e1) != g2.get_edge_attribute(e2):
continue
if g1.get_node_attribute(e1[0]) != g2.get_node_attribute(e2[0]):
continue
if g1.get_node_attribute(e1[1]) != g2.get_node_attribute(e2[1]):
continue
# the two edges match
# print("edge matches:" + str(e1) + str(e2))
# print(g1.get_edge_attribute(e1),g2.get_edge_attribute(e2))
result.add_vertex((e1, e2))
# add edges in r (between edge pairs that are compatible)
# print(len(result.vertices()))
product_nodes = result.vertices()
for i in range(len(product_nodes)):
for j in range(i+1, len(product_nodes)):
ee1 = product_nodes[i]
ee2 = product_nodes[j]
if ee1 == ee2:
continue
middle_node1 = None
middle_node2 = None
for v1 in ee1[0]:
for v2 in ee2[0]:
if v1 == v2:
middle_node1 = v1
for v1 in ee1[1]:
for v2 in ee2[1]:
if v1 == v2:
middle_node2 = v1
result.add_edge((ee1,ee2))
if middle_node1 == None or middle_node2 == None:
# print("d_edge setting : ", ee1, ee2)
result.set_edge_attribute({(ee1,ee2) : "d-edge"})
elif g1.get_node_attribute(middle_node1) == g2.get_node_attribute(middle_node2):
result.set_edge_attribute({(ee1,ee2) : "c-edge"})
else:
# print("d_edge setting : ", ee1, ee2)
result.set_edge_attribute({(ee1,ee2) : "d-edge"})
# print(" resulting edge product graph: ")
# for e in result.edges():
# print(str(e))
# print(result.get_edge_attribute(e))
return result