initial stuff done
This commit is contained in:
parent
84f25c698c
commit
aed7f80c42
11
.drone.yml
Normal file
11
.drone.yml
Normal file
@ -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
|
@ -3,37 +3,35 @@ import networkx as nx
|
|||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
parser=argparse.ArgumentParser(description='')
|
parser = argparse.ArgumentParser(description='')
|
||||||
parser.add_argument('-g', '--graph', dest='graph', action='store', default=None)
|
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('-d', '--destroy', dest='destroy', action='store', default=None)
|
||||||
parser.add_argument('-n', '--node', dest='isnode', action='store_const', const=False, default = True)
|
parser.add_argument('-n', '--node', dest='isnode', action='store_const', const=False, default=True)
|
||||||
args=parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.graph or not args.destroy:
|
if not args.graph or not args.destroy:
|
||||||
print >> sys.stderr, 'need graph and destroylist as argument -g and/or -m'
|
sys.stderr.write('need graph and destroylist as argument -g and/or -m')
|
||||||
exit()
|
exit(1)
|
||||||
|
|
||||||
D=[]
|
D = []
|
||||||
with open(args.destroy) as inf:
|
with open(args.destroy) as inf:
|
||||||
for line in inf:
|
for line in inf:
|
||||||
D.append(int(line))
|
D.append(int(line))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
with open(args.graph) as ing:
|
with open(args.graph) as ing:
|
||||||
n=int(ing.readline())
|
n = int(ing.readline())
|
||||||
m=int(ing.readline())
|
m = int(ing.readline())
|
||||||
A=[[0]*n for _ in range(n)]
|
A = [[0] * n for _ in range(n)]
|
||||||
for _ in range(m):
|
for _ in range(m):
|
||||||
if not args.isnode:
|
if not args.isnode:
|
||||||
if _ in D:
|
if _ in D:
|
||||||
continue
|
continue
|
||||||
[u,v]=map(int, ing.readline().split())
|
[u, v] = map(int, ing.readline().split())
|
||||||
if args.isnode:
|
if args.isnode:
|
||||||
if u in D or v in D:
|
if u in D or v in D:
|
||||||
continue
|
continue
|
||||||
A[u][v]=1
|
A[u][v] = 1
|
||||||
A[v][u]=1
|
A[v][u] = 1
|
||||||
G=nx.Graph(np.array(A))
|
G = nx.Graph(np.array(A))
|
||||||
|
|
||||||
print (len(D), [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)] )
|
print(len(D), [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)])
|
||||||
|
@ -2,40 +2,43 @@ import numpy as np
|
|||||||
import networkx as nx
|
import networkx as nx
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser=argparse.ArgumentParser(description='')
|
parser = argparse.ArgumentParser(description='')
|
||||||
parser.add_argument('-g', '--graph', dest='graph', action='store', default=None)
|
parser.add_argument('-g', '--graph', dest='graph', action='store', default=None)
|
||||||
args=parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not args.graph:
|
if not args.graph:
|
||||||
print ("need a graph as input")
|
print("need a graph as input")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def read_graph(graph_file):
|
def read_graph(graph_file):
|
||||||
with open(graph_file) as f:
|
with open(graph_file) as f:
|
||||||
n=int(f.readline())
|
n = int(f.readline())
|
||||||
m=int(f.readline())
|
m = int(f.readline())
|
||||||
A=[[0]*n for _ in range(n)]
|
A = [[0] * n for _ in range(n)]
|
||||||
for _ in range(m):
|
for _ in range(m):
|
||||||
[u,v]=map(int, f.readline().split())
|
[u, v] = map(int, f.readline().split())
|
||||||
A[u][v]=1
|
A[u][v] = 1
|
||||||
A[v][u]=1
|
A[v][u] = 1
|
||||||
G=nx.Graph(np.array(A))
|
G = nx.Graph(np.array(A))
|
||||||
return G
|
return G
|
||||||
|
|
||||||
|
|
||||||
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)])
|
||||||
|
|
||||||
del_list=[]
|
|
||||||
G=read_graph(args.graph)
|
del_list = []
|
||||||
n=len(G.nodes)
|
G = read_graph(args.graph)
|
||||||
while max_comp_size(G) > n/2:
|
n = len(G.nodes)
|
||||||
u=np.random.choice(G.nodes)
|
while max_comp_size(G) > n / 2:
|
||||||
|
u = np.random.choice(G.nodes)
|
||||||
if u not in del_list:
|
if u not in del_list:
|
||||||
del_list.append(u)
|
del_list.append(u)
|
||||||
G.remove_node(u)
|
G.remove_node(u)
|
||||||
|
|
||||||
#print len(del_list), del_list
|
# print len(del_list), del_list
|
||||||
|
|
||||||
|
|
||||||
for u in del_list:
|
for u in del_list:
|
||||||
print (u)
|
print(u)
|
||||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
numpy
|
||||||
|
networkx
|
Loading…
Reference in New Issue
Block a user