(G, start_id, return_bfs=False)
get a bfs node sequence
    :param G:
    :param start_id:
    :return:
get a bfs node sequence
    :param G:
    :param start_id:
    :return:
get a bfs node sequence : param G : : param start_id : : return :
def bfs_seq(G, start_id, return_bfs=False):
    '''
    get a bfs node sequence
    :param G:
    :param start_id:
    :return:
    '''
    dictionary = dict(nx.bfs_successors(G, start_id))
    start = [start_id]
    output = [start_id]
    while len(start) > 0:
        next = []
        while len(start) > 0:
            current = start.pop(0)
            neighbor = dictionary.get(current)
            if neighbor is not None:
                #### a wrong example, should not permute here!
                # shuffle(neighbor)
                next = next + neighbor
        output = output + next
        start = next
    if return_bfs:
        remap = {}
        for i in range(len(output)):
            remap[output[i]] = i
        bfs_dict = {}
        for key in dictionary.keys():
            bfs_dict[remap[key]] = []
            for j in range(len(dictionary[key])):
                bfs_dict[remap[key]].append(remap[dictionary[key][j]])
        nodes = list(range(len(output)))
        parents = list(np.zeros(len(nodes), dtype="int"))
        zeros_neighb = []
        for key in bfs_dict.keys():
            for j in range(len(bfs_dict[key])):
                parents[bfs_dict[key][j]] = key
        return output, nodes, parents, bfs_dict
    else:
        return output
def bfs_seq ( G , start_id , return_bfs = False ) : dictionary = dict ( nx . bfs_successors ( G , start_id ) ) start = [ start_id ] output = [ start_id ] while len ( start ) > 0 : next = [ ] while len ( start ) > 0 : current = start . pop ( 0 ) neighbor = dictionary . get ( current ) if neighbor is not None : #### a wrong example, should not permute here! # shuffle(neighbor) next = next + neighbor output = output + next start = next if return_bfs : remap = { } for i in range ( len ( output ) ) : remap [ output [ i ] ] = i bfs_dict = { } for key in dictionary . keys ( ) : bfs_dict [ remap [ key ] ] = [ ] for j in range ( len ( dictionary [ key ] ) ) : bfs_dict [ remap [ key ] ] . append ( remap [ dictionary [ key ] [ j ] ] ) nodes = list ( range ( len ( output ) ) ) parents = list ( np . zeros ( len ( nodes ) , dtype = "int" ) ) zeros_neighb = [ ] for key in bfs_dict . keys ( ) : for j in range ( len ( bfs_dict [ key ] ) ) : parents [ bfs_dict [ key ] [ j ] ] = key return output , nodes , parents , bfs_dict else : return output