def test_construct_treechild_already_treechild(self):
     g = nx.DiGraph()
     g.add_edges_from([ ((1,), (2,)) ])
     self.assertTrue(is_treechild(g))
     tcs = construct_treechild(g)
     gold = []
     self.assertItemsEqual(tcs, gold)
 def test_construct(self):
     tree_childs = construct_treechild(self.G)
     self.assertEqual(len(tree_childs), 1)
     graph_gold = self.G.copy()
     graph_gold.remove_edge(u="1,2", v='2h')
     graph_gold.remove_node('2h')
     graph_gold.remove_node("1,2")
     gold = [graph_gold, ]
     for tc, gg in zip(tree_childs, gold):
         self.assertItemsEqual(tc.nodes(), gg.nodes())
 def test_construct(self):
     graph_gold_left = self.G.copy()
     graph_gold_left.remove_edge(u="1,2,3", v='3h')
     graph_gold_left.remove_node("1,2,3")
     graph_gold_left.remove_node("3h")
     graph_gold_right = self.G.copy()
     graph_gold_right.remove_edge(u="4,5", v="4h")
     graph_gold_right.remove_node("4,5")
     graph_gold_right.remove_node('4h')
     gold = [graph_gold_right, graph_gold_left, ]
     tree_childs = construct_treechild(self.G)
     self.assertEqual(len(tree_childs), 2)
     for tc, gg in zip(tree_childs, gold):
         self.assertItemsEqual(tc.nodes(), gg.nodes())
Beispiel #4
0
def test_case(g):
    test = TEST_NUMBER
    nodes = len(g.nodes())
    fulles = len(get_leaf_nodes(g))
    arestes = len(g.edges())
    hibrids = len(hybrid_nodes(g))
    grau_hibriditzacio = hybridization_degree(g)
    arestes_llevables = len(removable_edges(g))
    es_treechild = is_treechild(g)
    nodes_conflictius = len(problematic_treechild_nodes(g))
    subarbres = potential_number_of_calls(g)
    # soft
    if subarbres < MAX_SUBARBRES:
        begin_soft = time.time()
        cluster_soft_cache(g)
        end_soft = time.time()
        temps_soft = end_soft - begin_soft
        begin_soft_cache = time.time()
        for i in range(SOFT_TIMES):
            cluster_soft_cache(g)
        end_soft_cache = time.time()
        temps_soft_cache = (end_soft_cache - begin_soft_cache) / SOFT_TIMES
    else:
        temps_soft, temps_soft_cache = -1, -1
    # tree-child
    if not es_treechild:
        begin_families = time.time()
        families = construct_treechild(g)
        end_families = time.time()
        n_families = len(families)
        temps_families = end_families - begin_families
    else:
        n_families, temps_families = 0, 0
    BenchmarkCase.create(
        test = test,
        fulles = fulles,
        nodes = nodes,
        arestes = arestes,
        hibrids = hibrids,
        subarbres = subarbres,
        grau_hibriditzacio = grau_hibriditzacio,
        temps_soft = temps_soft,
        temps_soft_cache = temps_soft_cache,
        arestes_llevables = arestes_llevables,
        es_treechild = es_treechild,
        nodes_conflictius = nodes_conflictius,
        temps_families = temps_families,
        n_families = n_families,
    )
def benchmark_nets(g):
    # atributs varis
    arestes_llevables = len(removable_edges(g))
    fulles = len(get_leaf_nodes(g))
    nodes = len(g.nodes())
    arestes = len(g.edges())
    hibrids = len(hybrid_nodes(g))
    grau_hibriditzacio = hybridization_degree(g)
    es_treechild = is_treechild(g)
    nodes_conflictius = len(problematic_treechild_nodes(g))
    subarbres = potential_number_of_calls(g)
    temps_soft, temps_soft_cache = -1, -1
    n_families, temps_families = -1, -1
    # tree-child
    if not es_treechild:
        if arestes_llevables < MAX_ARESTES:
            begin_families = time.time()
            families = construct_treechild(g)
            end_families = time.time()
            temps_families = end_families - begin_families
            n_families = len(families)
    else:
        n_families, temps_families = 0, 0
    BenchmarkCase.create(
        test=TEST_NUMBER,
        fulles=fulles,
        nodes=nodes,
        arestes=arestes,
        hibrids=hibrids,
        subarbres=subarbres,
        grau_hibriditzacio=grau_hibriditzacio,
        temps_soft=temps_soft,
        temps_soft_cache=temps_soft_cache,
        arestes_llevables=arestes_llevables,
        es_treechild=es_treechild,
        nodes_conflictius=nodes_conflictius,
        temps_families=temps_families,
        n_families=n_families,
    )
 def test_random_1(self):
     clusters = [(1, 5, 7, 10), (2, 4, 8, 10), (1, 3), (3, 4)]
     gold = 0
     result = construct_treechild(construct(clusters))
     self.assertEqual(len(result), gold)
 def test_construct_treechild_empty(self):
     empty = nx.DiGraph()
     tcs = construct_treechild(empty)
     gold = []
     self.assertItemsEqual(tcs, gold)
 def test_construct(self):
     tree_childs = construct_treechild(self.G)
     gold = []
     self.assertItemsEqual(tree_childs, gold)