用法:
cugraph.traversal.bfs.bfs(G, start=None, depth_limit=None, i_start=None, directed=None, return_predecessors=None)
查找圖的廣度優先遍曆的距離和前輩。
- G:cugraph.Graph、networkx.Graph、CuPy 或 SciPy 稀疏矩陣
圖形或矩陣對象,應包含連通性信息。邊權重(如果存在)應該是單精度或雙精度浮點值。
- start:整數,可選(默認=無)
遍曆開始的圖頂點的索引
- depth_limit:整數或無,可選(默認=無)
限製搜索的深度
- i_start:整數,可選(默認=無)
與開始相同,為 API 兼容性而添加。隻能設置 start 或 i_start,不能同時設置。
- directed:布爾,可選(默認=無)
- NOTE
僅適用於 G 的非圖形類型(例如稀疏矩陣)值。如果與 Graph 對象一起使用,則引發 TypeError。
如果為 True,則將輸入矩陣轉換為 cugraph.DiGraph,否則將使用 cugraph.Graph 對象。
- return_predecessors:
- 返回值類型基於輸入類型。如果 G 是一個 cugraph.Graph,
- 返回:
- cudf.DataFrame
df[‘vertex’] 頂點 ID
df[‘distance’] 每個頂點到起始頂點的路徑距離
df[‘predecessor’] 對於列中的每個第 i 個位置,緊接在 ‘vertex’ 列中位置 i 處的頂點之前的頂點 ID
- 如果 G 是 networkx.Graph,則返回:
pandas.DataFrame 的內容與上述 cudf.DataFrame 相同。
- 如果 G 是 CuPy 或 SciPy 矩陣,則返回:
CuPy ndarrays(如果 CuPy 矩陣輸入)或 Numpy ndarrays(如果 SciPy 矩陣輸入)的 2 元組,表示:
- 距離:cupy 或 numpy ndarray
源和頂點之間最短距離的ndarray。
- 前身:cupy 或 numpy ndarray
來自源的路徑上頂點的前驅的ndarray,可用於重建最短路徑。
…或者如果 return_sp_counter 為 True,則返回一個 3 元組,其中包含上述兩個數組加上:
- sp_counter:cupy 或 numpy ndarray
ndarray 通向每個頂點的最短路徑數。
參數:
返回:
例子:
>>> M = cudf.read_csv(datasets_path / 'karate.csv', delimiter=' ', ... dtype=['int32', 'int32', 'float32'], header=None) >>> G = cugraph.Graph() >>> G.from_cudf_edgelist(M, source='0', destination='1') >>> df = cugraph.bfs(G, 0)
相關用法
- Python cugraph.traversal.bfs.bfs_edges用法及代碼示例
- Python cugraph.traversal.sssp.sssp用法及代碼示例
- Python cugraph.tree.minimum_spanning_tree.maximum_spanning_tree用法及代碼示例
- Python cugraph.tree.minimum_spanning_tree.minimum_spanning_tree用法及代碼示例
- Python cugraph.community.spectral_clustering.spectralBalancedCutClustering用法及代碼示例
- Python cugraph.link_prediction.jaccard.jaccard用法及代碼示例
- Python cugraph.link_prediction.wjaccard.jaccard_w用法及代碼示例
- Python cugraph.community.ecg.ecg用法及代碼示例
- Python cugraph.Graph.from_cudf_adjlist用法及代碼示例
- Python cugraph.community.louvain.louvain用法及代碼示例
- Python cugraph.centrality.betweenness_centrality.betweenness_centrality用法及代碼示例
- Python cugraph.link_analysis.pagerank.pagerank用法及代碼示例
- Python cugraph.dask.community.louvain.louvain用法及代碼示例
- Python cugraph.community.egonet.batched_ego_graphs用法及代碼示例
- Python cugraph.Graph.from_cudf_edgelist用法及代碼示例
- Python cugraph.centrality.betweenness_centrality.edge_betweenness_centrality用法及代碼示例
- Python cugraph.link_prediction.woverlap.overlap_w用法及代碼示例
- Python cugraph.link_prediction.overlap.overlap用法及代碼示例
- Python cugraph.link_prediction.jaccard.jaccard_coefficient用法及代碼示例
- Python cugraph.components.connectivity.strongly_connected_components用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cugraph.traversal.bfs.bfs。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。