示例#1
0
def ring_local_stitching(samples: List[nx.MultiDiGraph], bridges_amount: int):
    samples_amount = len(samples)
    if samples_amount < 2:
        return
    tails = [[choices(list(sample.nodes), k=bridges_amount) for _ in range(2)]
             for sample in samples]
    heads = [[choices(list(sample.nodes), k=bridges_amount) for _ in range(2)]
             for sample in samples]
    for i, sample in enumerate(samples):
        j = 0 if i == len(samples) - 1 else i + 1
        if i != j:
            sample.add_edges_from(zip(tails[i][0], heads[j][1]))
示例#2
0
def all_to_all_local_stitching(samples: List[nx.MultiDiGraph],
                               bridges_amount: int):
    samples_amount = len(samples)
    if samples_amount < 2:
        return
    tails = [[
        choices(list(sample.nodes), k=bridges_amount)
        for _ in range(len(samples))
    ] for sample in samples]
    heads = [[
        choices(list(sample.nodes), k=bridges_amount)
        for _ in range(len(samples))
    ] for sample in samples]
    for i, sample in enumerate(samples):
        for j in range(len(samples)):
            if i != j:
                sample.add_edges_from(zip(tails[i][j], heads[j][i]))
示例#3
0
def all_to_all_distributed_stitching(samples: List[nx.MultiDiGraph],
                                     bridges_amount: int):
    raw_samples = []
    for sample in samples:
        raw_samples.extend(sample.nodes)
    random.shuffle(raw_samples)
    my_remote_heads = [
        choices(raw_samples, k=bridges_amount) for _ in range(mpi.size)
    ]

    tails = [choices(raw_samples, k=bridges_amount) for _ in range(mpi.size)]
    remote_heads = mpi.comm.alltoall(my_remote_heads)
    for i in range(mpi.size):
        if i != mpi.rank:
            bridges_amount_i = min(len(remote_heads[i]), len(tails[i]))
            samples[0].add_edges_from(
                zip(remote_heads[i][:bridges_amount_i],
                    tails[i][:bridges_amount_i]))
示例#4
0
def local_edge_sampling(
        candidate_edges: List[Vertex],
        nodes_amount: int) -> Tuple[nx.MultiDiGraph, List[Vertex]]:
    subgraph = nx.MultiDiGraph()
    nodes_sampled = 0
    while nodes_sampled < nodes_amount:
        subgraph.add_edges_from(
            choices(candidate_edges,
                    k=ceil((nodes_amount - nodes_sampled) / 2)))
        nodes_sampled = subgraph.number_of_nodes()
    candidate_edges = list(
        filter(lambda e: not subgraph.has_edge(*e), candidate_edges))
    return subgraph, candidate_edges