コード例 #1
0
def random_almost_equi_partitions_with_walk(graph, num_partitions, num_blocks, delta, step = "Basis", jump_size = 50):
    '''This produces a delta almost equi partition... it keeps looping until it finds
    the required amounts
    
    '''
#    print("am here")
#    print(step)
    found_partitions = []
    counter = 0
    tree = random_spanning_tree_wilson(graph)
    while len(found_partitions) < num_partitions:
        counter += 1
        if step == "Basis":
            for i in range(jump_size):
                tree, edge_to_remove, edge_to_add = propose_step(graph, tree)
        if step == "Broder":
            for i in range(jump_size):
                tree, edge_to_remove, edge_to_add = propose_Broder_step(graph, tree)
        edge_list = almost_equi_split(tree, num_blocks, delta)
        #If the almost equi split was not a delta split, then it returns none...
        if edge_list != None:
            blocks = remove_edges_map(graph, tree, edge_list)
            found_partitions.append(blocks)
            print(len(found_partitions), "waiting time:", counter)
            counter = 0
    return found_partitions
コード例 #2
0
def make_partition_list(graph, number_samples = 100, tree_algorithm = random_spanning_tree_wilson, equi = True):
    
    #Note -- currently this is configured only for 2 partitions
    total_number_trees_edges_pairs = np.exp(log_number_trees(graph))*(len(graph.nodes()) - 1)
    
    uniform_trees = []
    for i in range(number_samples):
        uniform_trees.append(tree_algorithm(graph))
        
    partitions = []
    for tree in uniform_trees:
        if equi == -1:
            e = random.choice(list(tree.edges()))
            blocks = remove_edges_map(graph, tree, [e])
            new_partition = partition_class(graph, blocks, tree, e, total_number_trees_edges_pairs)
            new_partition.set_likelihood()
            partitions.append(new_partition)
        else:
            out = almost_equi_split(tree, 2,.1)
            if out != None:
                e = out[0]
                blocks = remove_edges_map(graph, tree, [e])
                new_partition = partition_class(graph, blocks, tree, e, total_number_trees_edges_pairs)
                new_partition.set_likelihood()
                partitions.append(new_partition)
    return partitions
コード例 #3
0
def random_almost_equi_partitions(graph, num_partitions, num_blocks, delta):
    '''This produces a delta almost equi partition... it keeps looping until it finds
    the required amounts
    
    '''
    found_partitions = []
    counter = 0
    while len(found_partitions) < num_partitions:
        counter += 1
        tree = random_spanning_tree_wilson(graph)
        edge_list = almost_equi_split(tree, num_blocks, delta)
        #If the almost equi split was not a delta split, then it returns none...
        if edge_list != None:
            blocks = remove_edges_map(graph, tree, edge_list)
            found_partitions.append(blocks)
            print(len(found_partitions), "waiting time:", counter)
            counter = 0
    return found_partitions