kebab
This commit is contained in:
parent
ca44105fae
commit
602f7d4f1b
@ -3,7 +3,12 @@ type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: run_tournament
|
||||
- name: check_result
|
||||
image: "python:3.8"
|
||||
commands:
|
||||
- pip3 install -r requirements.txt
|
||||
- python3 destroy_p3.py -g GBA1000.txt
|
||||
- name: check_result
|
||||
image: "python:3.8"
|
||||
commands:
|
||||
- pip3 install -r requirements.txt
|
||||
|
@ -13,9 +13,9 @@ if not args.graph:
|
||||
|
||||
def read_graph(graph_file):
|
||||
with open(graph_file) as f:
|
||||
n = int(f.readline())
|
||||
m = int(f.readline())
|
||||
A = [[0] * n for _ in range(n)]
|
||||
n = int(f.readline()) # pontok száma
|
||||
m = int(f.readline()) # élek száma
|
||||
A = [[0] * n for _ in range(n)] # táblázat, ahol az élek helyén 1 van, ammeg 0
|
||||
for _ in range(m):
|
||||
[u, v] = map(int, f.readline().split())
|
||||
A[u][v] = 1
|
||||
@ -24,19 +24,44 @@ def read_graph(graph_file):
|
||||
return G
|
||||
|
||||
|
||||
input_graph = read_graph(args.graph)
|
||||
|
||||
|
||||
def max_comp_size(G):
|
||||
return max([len(c) for c in nx.connected_components(G)])
|
||||
|
||||
|
||||
def run_random_once() -> list:
|
||||
del_list = []
|
||||
G = read_graph(args.graph)
|
||||
n = len(G.nodes)
|
||||
while max_comp_size(G) > n / 2:
|
||||
H = max((G.subgraph(c) for c in nx.connected_components(G)), key=len)
|
||||
mnc = nx.minimum_node_cut(G=H)
|
||||
del_list.append(mnc)
|
||||
G.remove_nodes_from(mnc)
|
||||
G = input_graph.copy()
|
||||
target = len(G.nodes) / 2
|
||||
while max_comp_size(G) > target:
|
||||
u = np.random.choice(G.nodes)
|
||||
if u not in del_list:
|
||||
del_list.append(u)
|
||||
G.remove_node(u)
|
||||
|
||||
return del_list
|
||||
|
||||
|
||||
for u in del_list:
|
||||
print(u)
|
||||
def remove_highest_kebab() -> list:
|
||||
del_list = []
|
||||
G = input_graph.copy()
|
||||
target = len(G.nodes) / 2
|
||||
|
||||
while max_comp_size(G) > target:
|
||||
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)
|
||||
|
||||
return del_list
|
||||
|
||||
|
||||
for kebab in remove_highest_kebab():
|
||||
print(kebab)
|
||||
|
Loading…
Reference in New Issue
Block a user