本文整理汇总了Python中igraph.Graph.get_all_shortest_paths方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.get_all_shortest_paths方法的具体用法?Python Graph.get_all_shortest_paths怎么用?Python Graph.get_all_shortest_paths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.get_all_shortest_paths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: part_three
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import get_all_shortest_paths [as 别名]
#.........这里部分代码省略.........
# Map valid neighbour points as skeleton points: snap to closest
# Show the resulting image
# Add Connected Object only if it has at least one valid cursor
# position
if len(valid_cursor_to_global) > 0:
valid_cursors.append(valid_cursor_to_global)
if len(valid_cursor_timestamps) > 0:
valid_cursor_timestamps_global.append(valid_cursor_timestamps)
# print 'global: ' + str(valid_cursor_to_global)
# Here we have the all the cursor positions for this image.
# Use these to find paths between the data point
# Data points are in: data_pts_thinned, we can use this
# datastructure to map data points to an index
g = Graph()
g.add_vertices(len(data_pts_thinned))
# Create an adjacency matrix of data points - based on
# 8-connectivity
g.add_edges(compute_all_edges(data_pts_thinned))
g.vs["point"] = data_pts_thinned
# Calculate Paths between cursor positions
path_points_ordered = [] # contains the temporal information, this
# is used for in-between points as well
path_points = []
for index_cursor_point in range(1, len(valid_cursor_local)):
start_vertex = g.vs.find(
point=valid_cursor_local[index_cursor_point - 1])
end_vertex = g.vs.find(
point=valid_cursor_local[index_cursor_point])
shortest_path = g.get_all_shortest_paths(
start_vertex, end_vertex)
if len(shortest_path) == 0:
print("In image: " + connected_image +
", No path exists between: " +
str(data_pts_thinned[index_cursor_point - 1]) +
str(" and ") +
str(data_pts_thinned[index_cursor_point]))
path_points_ordered.append([])
# If no connection, still keep path_points_ordered same in
# size, need it at the end
else:
# Path exists
path_between_strokes = []
for _path_points in shortest_path[0]:
# shortest path contains an array of shortest paths,
# meaning there could be more than one,
# I take the first one, doesn't make any difference
# color_img[g.vs[_path_points]['point']] = [0,0,0]
path_points.append(g.vs[_path_points]['point'])
# Save path points so that we can delete them later on
path_between_strokes.append(
g.vs[_path_points]['point'])
# print 'start: ' + str(start_vertex['point'])
# print 'end: ' + str(end_vertex['point'])
# print 'path: ' + str(path_points)
path_points_ordered.append(path_between_strokes)