def breadth_first_search(A, start): """ Breadth-First-Search (BFS) of a graph in CSR or CSC matrix format starting from a given node (row). Takes Qobjs and CSR or CSC matrices as inputs. This function requires a matrix with symmetric structure. Use A+trans(A) if original matrix is not symmetric or not sure. Parameters ---------- A : csc_matrix, csr_matrix Input graph in CSC or CSR matrix format start : int Staring node for BFS traversal. Returns ------- order : array Order in which nodes are traversed from starting node. levels : array Level of the nodes in the order that they are traversed. """ if not (sp.isspmatrix_csc(A) or sp.isspmatrix_csr(A)): raise TypeError('Input must be CSC or CSR sparse matrix.') num_rows = A.shape[0] start = int(start) order, levels = _breadth_first_search(A.indices, A.indptr, num_rows, start) # since maybe not all nodes are in search, check for unused entires in # arrays return order[order != -1], levels[levels != -1]
def breadth_first_search(A, start): """ Breadth-First-Search (BFS) of a graph in CSR or CSC matrix format starting from a given node (row). Takes Qobjs and CSR or CSC matrices as inputs. This function requires a matrix with symmetric structure. Use A+trans(A) if original matrix is not symmetric or not sure. Parameters ---------- A : qobj, csr_matrix Input graph in CSR matrix form start : int Staring node for BFS traversal. Returns ------- order : array Order in which nodes are traversed from starting node. levels : array Level of the nodes in the order that they are traversed. """ if A.__class__.__name__ == 'Qobj': A = A.data num_rows = A.shape[0] start = int(start) order, levels = _breadth_first_search(A.indices, A.indptr, num_rows, start) #since maybe not all nodes are in search, check for unused entires in arrays return order[order != -1], levels[levels != -1]
def breadth_first_search(A,start): """ Breadth-First-Search (BFS) of a graph in CSR or CSC matrix format starting from a given node (row). Takes Qobjs and CSR or CSC matrices as inputs. This function requires a matrix with symmetric structure. Use A+trans(A) if original matrix is not symmetric or not sure. Parameters ---------- A : qobj, csr_matrix Input graph in CSR matrix form start : int Staring node for BFS traversal. Returns ------- order : array Order in which nodes are traversed from starting node. levels : array Level of the nodes in the order that they are traversed. """ if A.__class__.__name__=='Qobj': A=A.data num_rows=A.shape[0] start=int(start) order, levels = _breadth_first_search(A.indices,A.indptr, num_rows, start) #since maybe not all nodes are in search, check for unused entires in arrays return order[order!=-1], levels[levels!=-1]