Skip to content

Commit

Permalink
put back get_chunk_function
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrajniak committed May 29, 2024
1 parent 8fcdb0c commit f2c4950
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
import math


def get_chunk_function(ebc):
def get_chunk(nodes):
num_chunks = nxp.cpu_count()
nodes_ebc = {i: 0 for i in nodes}
for i in ebc:
nodes_ebc[i[0]] += ebc[i]
nodes_ebc[i[1]] += ebc[i]

sorted_nodes = sorted(nodes_ebc.items(), key=lambda x: x[1], reverse=True)
def test_betweenness_centrality_get_chunks():
def get_chunk_function(ebc):
def get_chunk(nodes):
num_chunks = nxp.cpu_count()
nodes_ebc = {i: 0 for i in nodes}
for i in ebc:
nodes_ebc[i[0]] += ebc[i]
nodes_ebc[i[1]] += ebc[i]

chunks = [[] for _ in range(num_chunks)]
chunk_sums = [0] * num_chunks
sorted_nodes = sorted(nodes_ebc.items(), key=lambda x: x[1], reverse=True)

for node, value in sorted_nodes:
min_chunk_index = chunk_sums.index(min(chunk_sums))
chunks[min_chunk_index].append(node)
chunk_sums[min_chunk_index] += value
chunks = [[] for _ in range(num_chunks)]
chunk_sums = [0] * num_chunks

return chunks
for node, value in sorted_nodes:
min_chunk_index = chunk_sums.index(min(chunk_sums))
chunks[min_chunk_index].append(node)
chunk_sums[min_chunk_index] += value

return get_chunk
return chunks

return get_chunk

def test_betweenness_centrality_get_chunks():
G = nx.fast_gnp_random_graph(100, 0.1, directed=False)
H = nxp.ParallelGraph(G)
ebc = nx.edge_betweenness_centrality(G)
Expand Down

0 comments on commit f2c4950

Please sign in to comment.