Exemplo n.º 1
0
def sort_graph(graph: tg.Graph):
    """
    Sort input Graph and save it in 'sorted_graphs' directory.

    :return: Path of sorted graph
    """
    txt_path = graph.get_file_path()
    directory, txt_name = txt_path.rsplit('/', 1)
    directory += '/'

    output_dir = directory + 'sorted_graphs/'
    create_dir(output_dir)

    output_path = output_dir + txt_name + '.sor'
    if not check_file_exists(output_path):
        print('Loading graph ' + txt_name + '...')
        m = np.loadtxt(txt_path, dtype=int, delimiter=' ', ndmin=2)
        print('Sorting graph ' + txt_name + '...')
        m = m[m[:, 2].argsort()]
        print('Saving sorted graph...')
        np.savetxt(output_path, m, fmt='%i', delimiter=' ')
        print('Saved! \n')
    else:
        print('File ' + output_path.rsplit('/', 1)[1] + ' already exist in ' +
              output_dir + '\n')
    return output_path
Exemplo n.º 2
0
def create_outdir(graph: tg.Graph, directory_name: str, txt_out_name: str):
    """
    Create output directory

    :param graph: A given Graph
    :param directory_name: Out directory name
    :param txt_out_name: Out txt file name
    :returns:
        - Input path of txt
        - Output path of out txt
    """
    txt_path = graph.get_file_path()
    directory, txt_name = txt_path.rsplit('/', 1)
    directory += '/'

    out_directory = directory + directory_name
    if out_directory[-1] != '/':
        out_directory += '/'

    create_dir(out_directory)

    output_path = out_directory + txt_name + '-' + txt_out_name
    return txt_path, output_path