예제 #1
0
def test_get_treewidth_from_peo():
    from qtree.graph_model.generators import generate_erdos_graph
    graph = generate_erdos_graph(50, 0.5)

    peo, tw1 = get_peo(graph)
    tw2 = get_treewidth_from_peo(graph, peo)
    print(f'treewidth: {tw2}, reference: {tw1}')
예제 #2
0
def test_method(method=get_upper_bound_peo_builtin):
    """
    Tests minfill heuristic using quickbb algorithm
    """
    from qtree.graph_model.base import wrap_general_graph_for_qtree
    from qtree.graph_model.generators import generate_erdos_graph

    # Test 1: path graph with treewidth 1
    print('Test 1. Path graph')
    graph = wrap_general_graph_for_qtree(nx.path_graph(8))

    peo1, tw1 = method(graph)
    peo2, tw2 = get_peo(graph)
    print(f'treewidth: {tw1}, reference: {tw2}')
    print(f'      peo: {peo1}\nreference: {peo2}')

    # Test 2: complete graph with treewidth n-1
    print('Test 2. Complete graph')
    graph = wrap_general_graph_for_qtree(nx.complete_graph(8))

    peo1, tw1 = method(graph)
    peo2, tw2 = get_peo(graph)
    print(f'treewidth: {tw1}, reference: {tw2}')
    print(f'      peo: {peo1}\nreference: {peo2}')

    # Test 3: complicated graphs with indefinite treewidth
    print('Test 3. Probabilistic graph')
    graph = wrap_general_graph_for_qtree(generate_erdos_graph(50, 0.5))

    peo1, tw1 = method(graph)
    peo2, tw2 = get_peo(graph)
    print(f'treewidth: {tw1}, reference: {tw2}')
    print(f'      peo: {peo1}\nreference: {peo2}')