Ejemplo n.º 1
0
 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 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
    # poda amb timeout
    # if arestes_llevables > MAX_ARESTES:
    #     return
    if not es_treechild:
        try:
            log.debug("inici construccio {}".format(arestes_llevables))
            executor = ThreadPoolExecutor(max_workers=1)
            begin_families = time.time()
            future = executor.submit(construct_treechild, g)
            families = future.result(TIMEOUT)
            end_families = time.time()
            temps_families = end_families - begin_families
            n_families = len(families)
            log.debug("final {}".format(arestes_llevables))
        except TimeoutError:
            log.debug("timeout {}".format(arestes_llevables))
            n_familes, temps_families = -1, -1
    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,
    )
Ejemplo n.º 3
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,
    )
Ejemplo n.º 4
0
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,
    )
Ejemplo n.º 5
0
 def test_true(self):
     clusters = [(1, 2), (3, 4)]
     G = construct(clusters)
     self.assertTrue(is_treechild(G))
Ejemplo n.º 6
0
 def test_complex_false(self):
     clusters = [(1, 2), (1, 3), (2, 3)]
     G = construct(clusters)
     self.assertFalse(is_treechild(G))
Ejemplo n.º 7
0
 def true_hybrid(self):
     "The fact to have hybrids does not mean you can't be tree-child"
     clusters = [(1, 2), (1, 3)]
     G = construct(clusters)
     self.assertTrue(is_treechild(G))
Ejemplo n.º 8
0
 def test_treechild(self):
     self.assertFalse(is_treechild(self.G))