Added predelete
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2020-09-24 21:47:13 +02:00
parent edbcefee93
commit cfd671a0f1

View File

@ -22,11 +22,29 @@ def worker(outqueue, id):
def max_comp_size(G): def max_comp_size(G):
return max([len(c) for c in nx.connected_components(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...") print(f"Worker {id} is working...")
while True: while True:
del_list = [] del_list = []
G = input_graph.copy() 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: while max_comp_size(G) > target:
u = np.random.choice(G.nodes) u = np.random.choice(G.nodes)
if u not in del_list: if u not in del_list: