コード例 #1
0
ファイル: stable.py プロジェクト: sthagen/SEPtAGe
def stable_partition_from_numpy(matrix, verbose=0):
    """
    It calculates the stable partition of a numpy adjacency matrix.

    :param matrix: numpy matrix
    :return:
    """
    edge_list = EdgeList(matrix, kind='numpy')
    partitions = iterable_partitions(edge_list.node_number)

    return find_stable_partition(partitions, edge_list)
コード例 #2
0
ファイル: stable.py プロジェクト: sthagen/SEPtAGe
def stable_partitions_from_networkx(G, verbose=0):
    """
    TODO: check if directed or undirected.
    :param G: a NetworkX graph.
    :return: an iterator over the list of stable partitions
    """

    partitions = iterable_partitions(len(G.nodes()))
    edge_list = EdgeList(G, kind='netwokrx')

    return find_stable_partition(partitions, edge_list)
コード例 #3
0
ファイル: main.py プロジェクト: sthagen/SEPtAGe
def testing_networkx():
    import networkx as nx

    G = nx.complete_graph(5)

    edges = EdgeList(G, kind='networkx')
    parts = iterable_partitions(edges.node_number)

    (time, results) = find_all_stable_partitions(parts, edges, verbose=0)
    assert results == []
    return "Test pass"
コード例 #4
0
ファイル: main.py プロジェクト: sthagen/SEPtAGe
def testing_numpy():
    import networkx as nx

    G = nx.complete_graph(5)
    matrix = nx.to_numpy_matrix(G)  # i'm lazy..

    edges = EdgeList(matrix, kind='numpy')
    parts = iterable_partitions(edges.node_number)

    (time, results) = find_all_stable_partitions(parts, edges, verbose=0)
    assert results == []
    return "Test pass"
コード例 #5
0
ファイル: stable.py プロジェクト: sthagen/SEPtAGe
def all_stable_partition_from_numpy(matrix, verbose=0):
    """
    It calculates the stable partition of a numpy adjacency matrix.

    :param matrix: numpy matrix
    :return:
    """

    edges = EdgeList(matrix, kind='numpy')
    parts = iterable_partitions(edges.node_number)
    stable_partitions = []

    for i in find_stable_partition(parts, edges, verbose):
        stable_partitions.append(i)
    return stable_partitions
コード例 #6
0
ファイル: main.py プロジェクト: sthagen/SEPtAGe
                        action='store_true',
                        dest='verbose')
    parser.add_argument('-o',
                        '--output',
                        help='the path of the output file',
                        dest='output_file')

    parsed_args = parser.parse_args()
    return parsed_args


if __name__ == '__main__':
    parser_args = menu()

    if parser_args.csv_file:
        edge_list = EdgeList(parser_args.csv_file, kind='csv')
        print("Input: ", parser_args.csv_file, ": ", edge_list.node_number,
              "nodes")
        if parser_args.verbose: print(edge_list.edge_list)
    else:
        edge_list = EdgeList(parser_args.numpy_file, kind='numpy')
        print("Input: ", parser_args.csv_file, ": ", edge_list.node_number,
              "nodes")
        if parser_args.verbose: print(edge_list.edge_list)

    partitions = iterable_partitions(edge_list.node_number)

    if parser_args.just_one:
        stable_partitions = find_stable_partition(partitions, edge_list,
                                                  parser_args.verbose)
        stable_partitions = [stable_partitions]