This commit is contained in:
parent
edbcefee93
commit
cfd671a0f1
@ -22,11 +22,29 @@ def worker(outqueue, id):
|
||||
def max_comp_size(G):
|
||||
return max([len(c) for c in nx.connected_components(G)])
|
||||
|
||||
predelete_count = int(id / 3)
|
||||
target = len(input_graph.nodes) / 2
|
||||
|
||||
if predelete_count:
|
||||
print(f"Worker {id} always deletes the {predelete_count} highest degree nodes")
|
||||
|
||||
print(f"Worker {id} is working...")
|
||||
while True:
|
||||
del_list = []
|
||||
G = input_graph.copy()
|
||||
target = len(G.nodes) / 2
|
||||
# A fresh new start
|
||||
|
||||
for _ in range(predelete_count):
|
||||
highest_node = None
|
||||
highest_node_deg = 0
|
||||
for node in G.nodes:
|
||||
if G.degree[node] > highest_node_deg:
|
||||
highest_node = node
|
||||
highest_node_deg = G.degree[node]
|
||||
|
||||
del_list.append(highest_node)
|
||||
G.remove_node(highest_node)
|
||||
|
||||
while max_comp_size(G) > target:
|
||||
u = np.random.choice(G.nodes)
|
||||
if u not in del_list:
|
||||
|
Loading…
Reference in New Issue
Block a user