本文整理匯總了Python中graph_tool.Graph.set_directed方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.set_directed方法的具體用法?Python Graph.set_directed怎麽用?Python Graph.set_directed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.set_directed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_graph
# 需要導入模塊: from graph_tool import Graph [as 別名]
# 或者: from graph_tool.Graph import set_directed [as 別名]
def create_graph(cls, edges, is_directed=True):
"""Create a graph-tool type graph from a list of edges"""
g = Graph()
g.set_directed(is_directed)
label2index = dict()
label = g.new_vertex_property('int32_t')
g.vertex_properties['label'] = label
for v1_label, v2_label in edges:
cls.add_vertex(v1_label, label2index, g)
cls.add_vertex(v2_label, label2index, g)
v1, v2 = label2index[v1_label], label2index[v2_label]
g.add_edge(v1, v2)
return g, label2index
示例2: edges_to_directed_tree
# 需要導入模塊: from graph_tool import Graph [as 別名]
# 或者: from graph_tool.Graph import set_directed [as 別名]
def edges_to_directed_tree(g, root, edges):
t = Graph(directed=False)
for _ in range(g.num_vertices()):
t.add_vertex()
for u, v in edges:
t.add_edge(u, v)
vis = EdgeCollectorVisitor()
bfs_search(t, source=root, visitor=vis)
t.clear_edges()
t.set_directed(True)
for u, v in vis.edges:
t.add_edge(u, v)
return filter_nodes_by_edges(t, edges)