From aed7f80c42508279c4116024c7e161a733cf48ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 24 Sep 2020 13:01:30 +0200 Subject: [PATCH] initial stuff done --- .drone.yml | 11 +++++++++++ analyse_p3.py | 32 +++++++++++++++----------------- destroy_p3.py | 37 ++++++++++++++++++++----------------- requirements.txt | 2 ++ 4 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 .drone.yml create mode 100644 requirements.txt diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..fec015c --- /dev/null +++ b/.drone.yml @@ -0,0 +1,11 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: run_tournament + image: "python:3.8" + commands: + - pip3 install -r requirements.txt + - python3 destroy_p3.py -g GBA1000.txt > gba1000d.txt + - python3 analyse_p3.py -g GBA1000.txt -d gba1000d.txt diff --git a/analyse_p3.py b/analyse_p3.py index f832228..78ae46e 100644 --- a/analyse_p3.py +++ b/analyse_p3.py @@ -3,37 +3,35 @@ import networkx as nx import argparse import sys -parser=argparse.ArgumentParser(description='') +parser = argparse.ArgumentParser(description='') parser.add_argument('-g', '--graph', dest='graph', action='store', default=None) parser.add_argument('-d', '--destroy', dest='destroy', action='store', default=None) -parser.add_argument('-n', '--node', dest='isnode', action='store_const', const=False, default = True) -args=parser.parse_args() +parser.add_argument('-n', '--node', dest='isnode', action='store_const', const=False, default=True) +args = parser.parse_args() if not args.graph or not args.destroy: - print >> sys.stderr, 'need graph and destroylist as argument -g and/or -m' - exit() + sys.stderr.write('need graph and destroylist as argument -g and/or -m') + exit(1) -D=[] +D = [] with open(args.destroy) as inf: for line in inf: D.append(int(line)) - - with open(args.graph) as ing: - n=int(ing.readline()) - m=int(ing.readline()) - A=[[0]*n for _ in range(n)] + n = int(ing.readline()) + m = int(ing.readline()) + A = [[0] * n for _ in range(n)] for _ in range(m): if not args.isnode: if _ in D: continue - [u,v]=map(int, ing.readline().split()) + [u, v] = map(int, ing.readline().split()) if args.isnode: if u in D or v in D: - continue - A[u][v]=1 - A[v][u]=1 - G=nx.Graph(np.array(A)) + continue + A[u][v] = 1 + A[v][u] = 1 + G = nx.Graph(np.array(A)) -print (len(D), [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)] ) \ No newline at end of file +print(len(D), [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)]) diff --git a/destroy_p3.py b/destroy_p3.py index 3ba93af..3e43722 100644 --- a/destroy_p3.py +++ b/destroy_p3.py @@ -2,40 +2,43 @@ import numpy as np import networkx as nx import argparse -parser=argparse.ArgumentParser(description='') +parser = argparse.ArgumentParser(description='') parser.add_argument('-g', '--graph', dest='graph', action='store', default=None) -args=parser.parse_args() +args = parser.parse_args() if not args.graph: - print ("need a graph as input") + print("need a graph as input") exit() + 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()) + m = int(f.readline()) + A = [[0] * n for _ in range(n)] for _ in range(m): - [u,v]=map(int, f.readline().split()) - A[u][v]=1 - A[v][u]=1 - G=nx.Graph(np.array(A)) + [u, v] = map(int, f.readline().split()) + A[u][v] = 1 + A[v][u] = 1 + G = nx.Graph(np.array(A)) return G + def max_comp_size(G): return max([len(c) for c in nx.connected_components(G)]) -del_list=[] -G=read_graph(args.graph) -n=len(G.nodes) -while max_comp_size(G) > n/2: - u=np.random.choice(G.nodes) + +del_list = [] +G = read_graph(args.graph) +n = len(G.nodes) +while max_comp_size(G) > n / 2: + u = np.random.choice(G.nodes) if u not in del_list: del_list.append(u) G.remove_node(u) -#print len(del_list), del_list +# print len(del_list), del_list for u in del_list: - print (u) \ No newline at end of file + print(u) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..61ab73d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +numpy +networkx \ No newline at end of file